ВОТ ТЕЛО МОЕГО ТЕСТА.
PHP код:
unit formMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TMainForm = class(TForm)
TaskBox: TListBox;
Panel1: TPanel;
CreateBtn: TButton;
CardsBox: TEdit;
QuestBox: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
procedure CreateBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
AppFolder: string;
end;
var
MainForm: TMainForm;
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(Sender: TObject);
var
tl, sl: TStringList;
i, j: integer;
s: string;
begin
Randomize;
AppFolder:= IncludeTrailingPathDelimiter( ExtractFilePath( ParamStr( 0 ) ) );
tl:= TStringList.Create;
sl:= TStringList.Create;
try
if FileExists( AppFolder + 'tasks.txt' ) then
begin
tl.LoadFromFile( AppFolder + 'tasks.txt' );
i:= -1;
while true do
begin
inc( i );
if i >= tl.Count then break;
if Pos( '[task', tl[i] ) = 0 then continue;
s:= tl[i];
Delete( s, 1, Length( '[task' ) );
if Pos( ']', s ) > 0 then
s:= Copy( s, 1, Pos( ']', s ) - 1 );
j:= i;
sl.Clear;
while true do
begin
inc( j );
if j >= tl.Count then break;
if Pos( '[task', tl[j] ) > 0 then break;
sl.Add( tl[j] );
end;
j:= StrToIntDef( s, 0 );
TaskBox.AddItem( IntToStr( j ) + ': ' + sl.Text, pointer( j ) );
end;
TaskBox.SelectAll;
end
else
begin
ShowMessage( 'Файл заданий tasks.txt не найден.' );
Application.Terminate;
exit;
end;
finally
sl.Free;
tl.Free;
end;
end;
procedure TMainForm.CreateBtnClick(Sender: TObject);
var
tl, cl, ql, qt: TStringList;
i, j, k, l: integer;
c, q: integer;
ImageFile: string;
s, s1: string;
QuestNumber: integer;
QuestNumbers: array of integer;
b: boolean;
begin
try
c:= StrToInt( CardsBox.Text );
except
ShowMessage( 'Ошибочное значение количества билетов.' );
exit;
end;
try
q:= StrToInt( QuestBox.Text );
except
ShowMessage( 'Ошибочное значение количества вопросов в билете.' );
exit;
end;
SetLength( QuestNumbers, q );
if not FileExists( AppFolder + 'card_template.htm' ) then
begin
ShowMessage( 'Не найден файл card_template.htm.' );
exit;
end;
if not FileExists( AppFolder + '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 - 1 do
if TaskBox.Selected[i] then
begin
s:= TaskBox.Items[i];
tl.AddObject( Copy( s, Pos( ': ', s ) + 2, MaxInt div 2 ),
TaskBox.Items.Objects[i] );
end;
if tl.Count < q then
begin
ShowMessage( 'Не хватает исходных вопросов для создания необходимых билетов.' );
exit;
end;
for i:= 1 to c do
begin
cl.LoadFromFile( AppFolder + 'card_template.htm' );
cl.Text:= Q_ReplaceStr( cl.Text, '$cnum', IntToStr( i ) );
s:= '';
for j:= 0 to q - 1 do
QuestNumbers[j]:= -1;
for j:= 1 to q do
begin
ql.LoadFromFile( AppFolder + 'quest_template.htm' );
ql.Text:= Q_ReplaceStr( ql.Text, '$qnum', IntToStr( j ) );
b:= true;
while b do
begin
l:= round( random * ( tl.Count - 1 ) );
QuestNumber:= integer( tl.Objects[l] );
b:= false;
for k:= 0 to q - 1 do
if QuestNumber = QuestNumbers[k] then b:= true;
end;
QuestNumbers[j - 1]:= QuestNumber;
s1:= '';
qt.Text:= tl[l];
for k:= 0 to qt.Count - 1 do
s1:= s1 + Q_ReplaceStr( QuestTextCode, '$qtext', qt[k] );
ql.Text:= Q_ReplaceStr( ql.Text, '$qtext', s1 );
ImageFile:= IntToStr( QuestNumber ) + '.jpg';
if FileExists( AppFolder + '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.
|