unit MethodAddrDemoUMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Menus, shellapi, ExtCtrls,
MethodAddrDemoUParser;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
StringGrid1: TStringGrid;
Memo1: TMemo;
Button4: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
Bevel3: TBevel;
PopupMenu1: TPopupMenu;
LineSummary1: TMenuItem;
Duration1: TMenuItem;
TotalDuration1: TMenuItem;
AverageDuration1: TMenuItem;
TotalAccess1: TMenuItem;
AverageAccess1: TMenuItem;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Bevel4: TBevel;
Label1: TLabel;
Label2: TLabel;
Button5: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label2Click(Sender: TObject);
private
public
end;
TMenuManager = Class
Private
fData : Variant;
Procedure ClickHandler(Sender: TObject);
Public
Constructor Create;
Destructor Destroy; override;
End;
var
Form1: TForm1;
appelCount : integer = 0;
aMenuManager : TMenuManager;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
With Form1.StringGrid1 Do
Begin
Cells[0,0] := 'Event observed';
Cells[1,0] := 'First time observed';
Cells[2,0] := 'Last time observed';
Cells[3,0] := 'Number of occurences';
Cells[0,1] := 'A certain event';
Cells[0,2] := 'An other one';
Cells[0,3] := 'One more';
Cells[0,4] := 'The last one';
For i:= 1 To 4 Do
Cells[1,i] := DateTimeToStr(Now + (i/19.5));
For i:= 1 To 4 Do
Cells[2,i] := DateTimeToStr(Now + 2*(i/19.5));
For i:= 1 To 4 Do
Randomize;
For i:= 1 To 4 Do
Cells[3,i] := IntToStr(Random(1000));
End;
Memo1.Lines.Add('// Comment or uncomment lines using "//"');
Memo1.Lines.Add('AddStrings(1,2,3,4)');
Memo1.Lines.Add('AddIntegers(1,2,3,4)');
Memo1.Lines.Add('UserShowMessage(Here is a message)');
aMenuManager := TMenuManager.create();
PopUpMenu1.AutoPopup := False;
For i := 0 To popUpMenu1.Items.Count -1 Do
PopUpMenu1.Items[i].OnClick := aMenuManager.ClickHandler;
end;
procedure TForm1.Button1Click(Sender: TObject);
var aParsedLine: TParsedLine;
v: Variant;
i: Integer;
aPArserInstance: TLittleParser;
begin
aParserInstance := TLittleParser.Create;
For i:= 0 To Memo1.Lines.Count -1 Do
Begin
aPArsedLine := aParserInstance.GetParsedLine(Memo1.Lines[i]);
If aParsedLine.lnIsValide then
Begin
v := aParserInstance.ExecFuncByName(aParsedLine.lnMethodName,
aParsedLine.lnArguments);
If varIsStr(v) Then If v = '' Then exit;
If Not(VarIsNull(v))
Then Memo1.Lines[i] := Memo1.Lines[i] + ' : ' + varToStr(v)
Else Memo1.Lines[i] := Memo1.Lines[i] + ' : (Unknown method :'
+ aParsedLine.lnMethodName + ')';
End;
End;
aParserInstance.Free;
end;
procedure TForm1.Button2Click(Sender: TObject);
var aParsedLine: TParsedLine;
v: Variant;
aParserInstance: TLittleParser;
begin
aPArserInstance := TLittleParser.Create;
aPArsedLine := aParserInstance.GetParsedLine( TButton(Sender).Caption );
v := aPArserInstance.ExecFuncByName(aParsedLine.lnMethodName,
aParsedLine.lnArguments);
showMessage( varToStr( v ) );
aParserInstance.Free;
end;
procedure TForm1.Button3Click(Sender: TObject);
var aPointedRec: PPointedRec;
v: Variant;
aPArserInstance: TLittleParser;
begin
inc(appelCount);
new(aPointedRec);
aPointedRec.anInteger := appelCount;
aPointedRec.aSender := Sender;
v := Integer(aPointedRec);
aParserInstance := TLittleParser.Create;
showMessage( aPArserInstance.ExecFuncByName('HandlePointerValues', v) );
Dispose(aPointedRec);
end;
Constructor TMenuManager.Create;
Begin
Inherited;
self.fData := VarArrayCreate([0,2],varInteger);
End;
Destructor TMenuManager.Destroy;
Begin
VarArrayRedim(fData,0);
Inherited Destroy;
End;
Procedure TMenuManager.ClickHandler(Sender: TObject);
var aParser: TLittleParser;
s:String;
Begin
TRY
If Sender Is TMenuItem Then
Begin
s := StringReplace( TMenuItem(Sender).Caption, '&', '', [rfReplaceAll] );
aParser := TLittleParser.Create;
aParser.ExecProcByName( s, self.fData );
aParser.Free;
End;
EXCEPT; END;
End;
Type PStringGrid = ^TStringGrid;
procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var aCol, aRow: Integer;
i: Integer;
Begin
If not( button = mbRight ) Then Exit;
StringGrid1.MouseToCell(X, Y, aCol, aRow);
If (aCol = -1) Or (aRow = -1) Then exit;
i := Integer( PStringGrid( StringGrid1 ) );
aMenuManager.fData[0] := VarAsType (i, varInteger);
aMenuManager.fData[1] := VarAsType (aCol, varInteger);
aMenuManager.fData[2] := VarAsType (aRow, varInteger);
For i := 0 To PopUpMenu1.Items.Count -1 Do
PopUpMenu1.Items.Items[i].Visible := False;
Case aCol of
0 : Begin
If aRow = 0 Then exit
Else PopUpMenu1.Items.Items[0].Visible := True;
End;
1,2 : Begin
If aRow <> 0 Then PopUpMenu1.Items.Items[1].Visible := True;
PopUpMenu1.Items.Items[2].Visible := True;
PopUpMenu1.Items.Items[3].Visible := True;
End;
3 : Begin
PopUpMenu1.Items.Items[4].Visible := True;
PopUpMenu1.Items.Items[5].Visible := True;
End;
Else exit;
End;
PopUpMenu1.PopUp(StringGrid1.ClientOrigin.X + X,
StringGrid1.ClientOrigin.Y + Y);
End;
procedure TForm1.Label2Click(Sender: TObject);
begin
ShellExecute(Form1.Handle,'open',
PChar('http://mapage.noos.fr/qnno/pages/delphi_en.htm'),
nil,nil, SW_SHOWNORMAL);
end;
end.
|