desarrollosconsejeria/aulalinex-ltsp-alumno/4.2-2/aulalinexcuestionltsp/main.pas @ 23a384b9
23a384b9 | Elisa | unit main;
|
|
{$mode objfpc}{$H+}
|
|||
interface
|
|||
uses
|
|||
IniFiles, IdURI,clrespuesta,Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
|||
StdCtrls, IdTCPClient, Buttons;
|
|||
type
|
|||
{ TfrmMain }
|
|||
TfrmMain = class(TForm)
|
|||
Image1: TImage;
|
|||
lblPregunta: TLabel;
|
|||
lblTiempo: TStaticText;
|
|||
tmrCuestion: TTimer;
|
|||
procedure FormCreate(Sender: TObject);
|
|||
procedure FormShow(Sender: TObject);
|
|||
procedure tmrCuestionTimer(Sender: TObject);
|
|||
procedure btnOpcionesClick(sender:TObject);
|
|||
private
|
|||
procedure CrearMemos;
|
|||
function LeerIni(): boolean;
|
|||
function tiempo(value: integer): string;
|
|||
{ private declarations }
|
|||
public
|
|||
procedure Finalizar;
|
|||
{ public declarations }
|
|||
end;
|
|||
var
|
|||
frmMain: TfrmMain;
|
|||
lblOpciones:Array of Tlabel;
|
|||
btnOpciones:Array of TButton;
|
|||
f_contador:integer;
|
|||
f_existe_custion:boolean;
|
|||
implementation
|
|||
uses global;
|
|||
Const
|
|||
DIR_CUSTION:string='%s/recibidos_profesor/.cuestion.ini';
|
|||
procedure TfrmMain.FormCreate(Sender: TObject);
|
|||
const
|
|||
SMI_HOST:string='echo $LTSP_CLIENT';
|
|||
begin
|
|||
SetBounds(0,0,1024,768);
|
|||
g_mihost:=HallarDato(SMI_HOST);
|
|||
g_hostprofe:='localhost';
|
|||
g_dirpersonal:=getenvironmentvariable('HOME');
|
|||
g_usuario:=getenvironmentvariable('USER');
|
|||
end;
|
|||
procedure TfrmMain.FormShow(Sender: TObject);
|
|||
begin
|
|||
if not LeerIni() then
|
|||
close;
|
|||
end;
|
|||
procedure TfrmMain.tmrCuestionTimer(Sender: TObject);
|
|||
var
|
|||
comando:string;
|
|||
begin
|
|||
f_contador:=f_contador-1;
|
|||
lbltiempo.caption:=Tiempo(f_contador);
|
|||
if f_contador = 0 then
|
|||
begin
|
|||
enabled:=false;
|
|||
hide;
|
|||
tmrCuestion.enabled:=false;
|
|||
g_tiempoempleado:=g_tiempo-f_contador;
|
|||
comando:='respuestaCuestion '+ TidUri.ParamsEncode(g_mihost) +' '+TidUri.ParamsEncode(g_Codigo)+' '+TidUri.ParamsEncode('0')+' '+TidUri.ParamsEncode(inttostr(g_tiempoempleado))+' '+TidUri.ParamsEncode(g_usuario);
|
|||
with ThrRespuesta.create(g_hostprofe,comando) do resume;
|
|||
end;
|
|||
end;
|
|||
procedure Tfrmmain.Finalizar;
|
|||
begin
|
|||
close;
|
|||
end;
|
|||
function Tfrmmain.tiempo(value:integer):string;
|
|||
var
|
|||
minutos,segundos:string;
|
|||
nsegundos:integer;
|
|||
begin
|
|||
minutos:='0'+inttostr(value div 60);
|
|||
nsegundos:=value mod 60;
|
|||
if value <10 then
|
|||
segundos:='0'+inttostr(nsegundos)
|
|||
else
|
|||
segundos:=inttostr(nsegundos);
|
|||
result:=minutos+':'+segundos;
|
|||
end;
|
|||
Function Tfrmmain.LeerIni():boolean;
|
|||
var
|
|||
Mifichero:TMemIniFile;
|
|||
dircuestion:string;
|
|||
i:integer;
|
|||
begin
|
|||
dircuestion:=Format(DIR_CUSTION,[g_dirpersonal]);
|
|||
result:=false;
|
|||
try
|
|||
if FileExists(dircuestion) then
|
|||
begin
|
|||
Mifichero:= TMemIniFile.create(dircuestion);
|
|||
try
|
|||
with MiFichero do
|
|||
begin
|
|||
g_codigo:=ReadString('TIPO','Codigo','');
|
|||
g_tipoc:=ReadString('TIPO','Tipo','0');
|
|||
g_tiempo:=ReadInteger('TIPO','Tiempo',30);
|
|||
g_num_opciones:=ReadInteger('TIPO','Numero_Opciones',0);
|
|||
if g_num_opciones>0 then
|
|||
begin
|
|||
setlength(g_opciones,g_num_opciones);
|
|||
setlength(lblOpciones,g_num_opciones);
|
|||
setlength(btnOpciones,g_num_opciones);
|
|||
g_pregunta:=ReadString('CUESTION','Pregunta', '');
|
|||
lblPregunta.caption:=TidUri.UrlDecode(g_pregunta);
|
|||
for i:=0 to high(g_opciones) do
|
|||
g_opciones[i]:=ReadString('CUESTION','Opcion_'+inttostr(i+1), '');
|
|||
CrearMemos()
|
|||
end;
|
|||
end;
|
|||
f_contador:=g_tiempo;
|
|||
tmrCuestion.enabled:=true;
|
|||
finally
|
|||
Mifichero.free;
|
|||
end;
|
|||
result:=true;
|
|||
end ;
|
|||
except
|
|||
result:=false;
|
|||
end;
|
|||
end;
|
|||
procedure Tfrmmain.CrearMemos;
|
|||
var i:integer;
|
|||
begin
|
|||
lblPregunta.font.size:=22;
|
|||
for i:=0 to high(lblOpciones) do
|
|||
begin
|
|||
lblOpciones[i]:=Tlabel.Create(self);
|
|||
btnOpciones[i]:=TButton.Create(self);
|
|||
with btnOpciones[i] do
|
|||
begin
|
|||
font.size:=20;
|
|||
width:=35;
|
|||
height:=35;
|
|||
cursor:=crHandPoint;
|
|||
Caption:= intToStr(i+1);
|
|||
Parent:=self;
|
|||
tag:=i+1;
|
|||
left:= lblpregunta.left-5;
|
|||
top:= lblpregunta.top + lblpregunta.height + 15 + (i*(10+lblpregunta.height-10));
|
|||
onClick:=@btnOpcionesClick;
|
|||
end;
|
|||
with lblOpciones[i] do
|
|||
begin
|
|||
font.size:=18;
|
|||
width:=lblpregunta.width-btnOpciones[i].width-10;
|
|||
height:=lblpregunta.height-10;
|
|||
Parent:=self;
|
|||
tag:=i+1;
|
|||
left:= btnOpciones[i].left+btnOpciones[i].width+10;
|
|||
top:= btnOpciones[i].top+10;
|
|||
text:=TidUri.UrlDecode(g_opciones[i]);
|
|||
end;
|
|||
end;
|
|||
end;
|
|||
procedure Tfrmmain.btnOpcionesClick(sender:TObject);
|
|||
var
|
|||
respuesta:integer;
|
|||
comando:string;
|
|||
begin
|
|||
try
|
|||
application.ProcessMessages;
|
|||
tmrCuestion.enabled:=false;
|
|||
hide;
|
|||
g_tiempoempleado:=g_tiempo-f_contador;
|
|||
respuesta:=(sender as Tbutton).tag;
|
|||
comando:='respuestaCuestion '+ TidUri.ParamsEncode(g_mihost) +' '+TidUri.ParamsEncode(g_Codigo)+' '+TidUri.ParamsEncode(inttostr(respuesta))+' '+TidUri.ParamsEncode(inttostr(g_tiempoempleado))+' '+TidUri.ParamsEncode(g_usuario);
|
|||
with ThrRespuesta.create(g_hostprofe,comando) do resume;
|
|||
except
|
|||
writeln('Error al emitir respuesta');
|
|||
end;
|
|||
end;
|
|||
initialization
|
|||
{$I main.lrs}
|
|||
end.
|