freelanceprogrammers.org Forum Index » Delphi

how to call Tbutton` method "Click"


View user's profile Post To page top
tocer_deng Posted: Wed May 24, 2006 9:14 am


Joined: 17 May 2006

Posts: 32
how to call Tbutton` method "Click"
Hi:

I write a demo, but it don`t work well.

I create two units below:
------------------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, PythonEngine, WrapDelphi, PythonGUIInputOutput;

type
TForm1 = class(TForm)
btnRun: TButton;
PythonGUIInputOutput1: TPythonGUIInputOutput;
PythonEngine1: TPythonEngine;
PyDelphiWrapper1: TPyDelphiWrapper;
PythonModule1: TPythonModule;
Memo1: TMemo;
Edit1: TEdit;
procedure FormShow(Sender: TObject);
procedure btnRunClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses WrapDelphiVCL,Unit2;

{$R *.dfm}


procedure TForm1.FormShow(Sender: TObject);
var
myform : TForm2;
p : PPyObject;
script : TStrings;
begin
myform := TForm2.Create(Application);
p := PyDelphiWrapper1.Wrap(myform);
PythonModule1.SetVar(`form`,p);
PythonEngine1.Py_DECREF(p);

script := TStringList.Create;
script.LoadFromFile(`e:delphiPython4Delphimy tutorialdemo4demo.py`);
try
PythonEngine1.ExecStrings(script);
finally
script.Free;
end;
end;

procedure TForm1.btnRunClick(Sender: TObject);
begin
GetPythonEngine.ExecString(Edit1.Text);
Edit1.Clear;
end;

end.
-----------------------------------------------

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
published
btnTest: TButton;
procedure btnTestClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.btnTestClick(Sender: TObject);
begin
ShowMessage(`Click Me`);
end;

end.
----------------------------------------------

my python code in demo.py is :

from Delphi import form

form.Show()
btn = form.btnTest
btn.Click()

----------------------------------------------


when I run this demo, error raised :

Project Project1.exe raised exception class EPyAttributeError with message
`AttributeError: `Button` object has no attribute `Click``. Process stopped.
Use Step or Run to continue.

I don`t know why not use Click method.

thans for any reply.

--tocer
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Thu May 25, 2006 5:30 am


Joined: 29 Apr 2005

Posts: 103
how to call Tbutton` method "Click"
Hi,

This does not work simply because the Click method was not wrapped. Wrapping
100% of the VCL manually is not realistic, so we had to implement first what
we considered most important. By and by, we`ll add more stuff based on the
user needs.
In this case, invoking Click by code is rarely useful. You still have a
workaround:

Drop a TActionList in the form, create a new action, bind it to your button
and replace your script with:

from Delphi import form

form.Show()
btn = form.btnTest
btn.Action.Execute()


Morgan

-----Original Message-----
From: pythonfordelphi@yahoogroups.com
[mailto:pythonfordelphi@yahoogroups.com] On Behalf Of tocer
Sent: May 24, 2006 12:15 AM
To: pythonfordelphi@yahoogroups.com
Subject: [pythonfordelphi] how to call Tbutton` method "Click"

Hi:

I write a demo, but it don`t work well.

I create two units below:
------------------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, PythonEngine, WrapDelphi, PythonGUIInputOutput;

type
TForm1 = class(TForm)
btnRun: TButton;
PythonGUIInputOutput1: TPythonGUIInputOutput;
PythonEngine1: TPythonEngine;
PyDelphiWrapper1: TPyDelphiWrapper;
PythonModule1: TPythonModule;
Memo1: TMemo;
Edit1: TEdit;
procedure FormShow(Sender: TObject);
procedure btnRunClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses WrapDelphiVCL,Unit2;

{$R *.dfm}


procedure TForm1.FormShow(Sender: TObject);
var
myform : TForm2;
p : PPyObject;
script : TStrings;
begin
myform := TForm2.Create(Application);
p := PyDelphiWrapper1.Wrap(myform);
PythonModule1.SetVar(`form`,p);
PythonEngine1.Py_DECREF(p);

script := TStringList.Create;
script.LoadFromFile(`e:delphiPython4Delphimy tutorialdemo4demo.py`);
try
PythonEngine1.ExecStrings(script);
finally
script.Free;
end;
end;

procedure TForm1.btnRunClick(Sender: TObject);
begin
GetPythonEngine.ExecString(Edit1.Text);
Edit1.Clear;
end;

end.
-----------------------------------------------

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
published
btnTest: TButton;
procedure btnTestClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.btnTestClick(Sender: TObject);
begin
ShowMessage(`Click Me`);
end;

end.
----------------------------------------------

my python code in demo.py is :

from Delphi import form

form.Show()
btn = form.btnTest
btn.Click()

----------------------------------------------


when I run this demo, error raised :

Project Project1.exe raised exception class EPyAttributeError with message
`AttributeError: `Button` object has no attribute `Click``. Process stopped.
Use Step or Run to continue.

I don`t know why not use Click method.

thans for any reply.

--tocer
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Thu May 25, 2006 6:33 am


Joined: 17 May 2006

Posts: 32
how to call Tbutton` method "Click"
Hi Morgan:

Thank you very much. it is not useful, and it is a demo only:)

The method you given is quiet useful to me. It can implement most call
from Python to Delphi. But if a properties is delared in public section,
how could I access it? Such as Cells in TStringGrid.

if I try to wrap more method or properites myself, would you like give
me some advice?

Thank your excellent job!

--tocer

Morgan Martinet wrote::
> Hi,
>
> This does not work simply because the Click method was not wrapped. Wrapping
> 100% of the VCL manually is not realistic, so we had to implement first what
> we considered most important. By and by, we`ll add more stuff based on the
> user needs.
> In this case, invoking Click by code is rarely useful. You still have a
> workaround:
>
> Drop a TActionList in the form, create a new action, bind it to your button
> and replace your script with:
>
> from Delphi import form
>
> form.Show()
> btn = form.btnTest
> btn.Action.Execute()
>
>
> Morgan
Reply with quote
Send private message
View user's profile Post To page top
tocer_deng Posted: Thu May 25, 2006 6:03 pm


Joined: 17 May 2006

Posts: 32
how to call Tbutton` method "Click"
I found I have to wrap manually public properties after reading p4d core code.
It seems not be too difficult and many code is similitude :)

--tocer

tocer wrote::
> Hi Morgan:
>
> Thank you very much. it is not useful, and it is a demo only:)
>
> The method you given is quiet useful to me. It can implement most call
> from Python to Delphi. But if a properties is delared in public section,
> how could I access it? Such as Cells in TStringGrid.
>
> if I try to wrap more method or properites myself, would you like give
> me some advice?
>
> Thank your excellent job!
>
> --tocer
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help