Показать сообщение отдельно
  #2  
Старый 06.11.2009, 22:55
SSkif SSkif вне форума
Прохожий
 
Регистрация: 05.11.2009
Сообщения: 6
Репутация: 10
По умолчанию

ВОТ ТЕЛО МОЕГО ТЕСТА.



PHP код:
unit formMain;

interface

uses
  Windows
MessagesSysUtilsVariantsClassesGraphicsControlsForms,
  
DialogsExtCtrlsStdCtrls;

type
  TMainForm 
= class(TForm)
    
TaskBoxTListBox;
    
Panel1TPanel;
    
CreateBtnTButton;
    
CardsBoxTEdit;
    
QuestBoxTEdit;
    
Label1TLabel;
    
Label2TLabel;
    
procedure FormCreate(SenderTObject);
    
procedure CreateBtnClick(SenderTObject);
  private
    { Private 
declarations }
  public
    { Public 
declarations }
    
AppFolderstring;
  
end;

var
  
MainFormTMainForm;

const
  
QuestTextCode '<p align="justify">$qtext</p>';
  
QuestImageCode '<p align="justify"><img border="0" src="$qimage"></p>';


implementation

{$R *.dfm}

uses QStrings;

procedure TMainForm.FormCreate(SenderTObject);
var
  
tlslTStringList;
  
ijinteger;
  
sstring;
begin
  Randomize
;

  
AppFolder:= IncludeTrailingPathDelimiterExtractFilePathParamStr) ) );

  
tl:= TStringList.Create;
  
sl:= TStringList.Create;
  try
    if 
FileExistsAppFolder 'tasks.txt' then
    begin
      tl
.LoadFromFileAppFolder 'tasks.txt' );

      
i:= -1;
      while 
true do
      
begin
        inc
);
        if 
>= tl.Count then break;
        if 
Pos'[task'tl[i] ) = 0 then continue;

        
s:= tl[i];
        
Deletes1Length'[task' ) );
        if 
Pos']') > 0 then
          s
:= Copys1Pos']') - );

        
j:= i;
        
sl.Clear;
        while 
true do
        
begin
          inc
);
          if 
>= tl.Count then break;
          if 
Pos'[task'tl[j] ) > 0 then break;

          
sl.Addtl[j] );
        
end;

        
j:= StrToIntDefs);
        
TaskBox.AddItemIntToStr) + ': ' sl.Textpointer) );
      
end;

      
TaskBox.SelectAll;
    
end
    
else
    
begin
      ShowMessage
'Файл заданий tasks.txt не найден.' );
      
Application.Terminate;
      exit;
    
end;
  
finally
    sl
.Free;
    
tl.Free;
  
end;
end;

procedure TMainForm.CreateBtnClick(SenderTObject);
var
  
tlclqlqtTStringList;
  
ijklinteger;
  
cqinteger;
  
ImageFilestring;
  
ss1string;
  
QuestNumberinteger;
  
QuestNumbers: array of integer;
  
bboolean;
begin
  
try
    
c:= StrToIntCardsBox.Text );
  
except
    ShowMessage
'Ошибочное значение количества билетов.' );
    exit;
  
end;

  try
    
q:= StrToIntQuestBox.Text );
  
except
    ShowMessage
'Ошибочное значение количества вопросов в билете.' );
    exit;
  
end;

  
SetLengthQuestNumbers);

  if 
not FileExistsAppFolder 'card_template.htm' then
  begin
    ShowMessage
'Не найден файл card_template.htm.' );
    exit;
  
end;

  if 
not FileExistsAppFolder 'quest_template.htm' then
  begin
    ShowMessage
'Не найден файл quest_template.htm.' );
    exit;
  
end;

  
tl:= TStringList.Create;
  
cl:= TStringList.Create;
  
ql:= TStringList.Create;
  
qt:= TStringList.Create;
  try
    for 
i:= 0 to TaskBox.Count do
      if 
TaskBox.Selected[ithen
      begin
        s
:= TaskBox.Items[i];
        
tl.AddObjectCopysPos': ') + 2MaxInt div 2 ),
                      
TaskBox.Items.Objects[i] );
      
end;

    if 
tl.Count q then
    begin
      ShowMessage
'Не хватает исходных вопросов для создания необходимых билетов.' );
      exit;
    
end;

    for 
i:= 1 to c do
    
begin
      cl
.LoadFromFileAppFolder 'card_template.htm' );
      
cl.Text:= Q_ReplaceStrcl.Text'$cnum'IntToStr) );

      
s:= '';
      for 
j:= 0 to q do
        
QuestNumbers[j]:= -1;

      for 
j:= 1 to q do
      
begin
        ql
.LoadFromFileAppFolder 'quest_template.htm' );
        
ql.Text:= Q_ReplaceStrql.Text'$qnum'IntToStr) );

        
b:= true;
        while 
do
        
begin
          l
:= roundrandom * ( tl.Count ) );
          
QuestNumber:= integertl.Objects[l] );
          
b:= false;

          for 
k:= 0 to q do
            if 
QuestNumber QuestNumbers[kthen b:= true;
        
end;
        
QuestNumbers[1]:= QuestNumber;

        
s1:= '';
        
qt.Text:= tl[l];
        for 
k:= 0 to qt.Count do
          
s1:= s1 Q_ReplaceStrQuestTextCode'$qtext'qt[k] );
        
ql.Text:= Q_ReplaceStrql.Text'$qtext's1 );

        
ImageFile:= IntToStrQuestNumber ) + '.jpg';
        if 
FileExistsAppFolder 'Images\' + ImageFile ) then
          ql.Add( Q_ReplaceStr( QuestImageCode, '
$qimage', 'Images/' + ImageFile ) );

        s:= s + ql.Text;
      end;

      cl.Text:= Q_ReplaceStr( cl.Text, '
$question', s );

      cl.SaveToFile( AppFolder + '
Card-' + Format( '%.3d', [i] ) + '.htm' );
    end;
  finally
    qt.Free;
    cl.Free;
    ql.Free;
    tl.Free;
  end;
end;

end. 
Ответить с цитированием