wqclatre
asked on
Pointer to a function or something.
I have a application and to that application I have a printing dll with a preview form in it.
What I like to do is on my Main Form (in the application)
set TMainForm.Printed := True if someone
Push the Print Button in the preview form.
Is this possible whitout include the TMainForm in the dll? I mean Can I send over a pointer to for example:
TMainForm.Printed ? (it's a boolean)
or eaven better. Can I send over a pointer to
TMainForm.SetPrinted (a procedure)
How?
What I like to do is on my Main Form (in the application)
set TMainForm.Printed := True if someone
Push the Print Button in the preview form.
Is this possible whitout include the TMainForm in the dll? I mean Can I send over a pointer to for example:
TMainForm.Printed ? (it's a boolean)
or eaven better. Can I send over a pointer to
TMainForm.SetPrinted (a procedure)
How?
In program main form declare a variable FPrinted:
private
{ Private declarations }
FPrinted: Boolean;
...
before you call the dll set FPrinted to false then send the address of FPrinted to the dl in the call using @:
FPrinted := False;
myPrintDllFunction(@FPrint ed);
In the dll declare the function parameter as a Pointer:
procedure myPrintDllFunction(aPrinte d: Pointer); export;
You can view the value by dereferencing the value aPrinted:
if Boolean(aPrinted^) then beep;
or change the value:
aPrinted^:= True;
All from head and untested, but might put you in the right direction.
Aubs
private
{ Private declarations }
FPrinted: Boolean;
...
before you call the dll set FPrinted to false then send the address of FPrinted to the dl in the call using @:
FPrinted := False;
myPrintDllFunction(@FPrint
In the dll declare the function parameter as a Pointer:
procedure myPrintDllFunction(aPrinte
You can view the value by dereferencing the value aPrinted:
if Boolean(aPrinted^) then beep;
or change the value:
aPrinted^:= True;
All from head and untested, but might put you in the right direction.
Aubs
ASKER
Cynna
you don't think you could give me an example of a)
(I don't know how to use handles
you don't think you could give me an example of a)
(I don't know how to use handles
ASKER
when I try to do:
Printed^:= True;
ist says: operator is not applicable to this operand type;
(I have Printed : Pointer;)
Printed^:= True;
ist says: operator is not applicable to this operand type;
(I have Printed : Pointer;)
ASKER
One problem I still will have is that I want to set a
checkbox when the item is printed.
It does not seems be possible to do:
FPrinted: Boolean;
cbPrinted : TCombobox;
myPrintDllFunction(@FPrint ed, @cbPrinted.checked);
checkbox when the item is printed.
It does not seems be possible to do:
FPrinted: Boolean;
cbPrinted : TCombobox;
myPrintDllFunction(@FPrint
ASKER
Sorry I mean
cbPrinted : TCheckBox.
cbPrinted : TCheckBox.
wqclatre,
1) In DLL:
*****************
1.1) Add:
const
UM_PRINT = WM_USER+1; // Custom message ID
var
MainFormHandle: HWND; // Global var stores MainFormHandle
(...)
1.2)
Assume your DLL print procedure is called Print.
Add additional argument to this procedure like this:
procedure Print(AHandle: HWND);
begin
// Store handle of the MainForm widow:
MainFormHandle:=AHandle;
//... rest of your code (deal with the printing)...
end;
So, when you call print from your main form, you'll
send its handle to DLL via Print() procedure. There
it's stored in global var for later reuse.
1.3)
When the printing is finished, and you want to notify
the MainForm obout this, just send it message like this:
// Inform MainForm that printing is finished:
SendMessage(MainFormHandle , UM_PRINT, 0, 0);
2) In EXE (MainForm):
************************** ***
2.1) Add custom message handler declaration like this:
const
UM_PRINT = WM_USER+1; // Custom message ID (same as in DLL)
Type
TForm1 = class(TForm)
...
procedure SetPrinted(var Msg: TMessage); message UM_PRINT;
...
end;
2.2) In definition do whatever you like:
procedure TForm1.SetPrinted(var Msg: TMessage);
// Called from DLL using SendMessage
begin
Caption:='Printing finished!';
end;
-------------------------- ---------
This method also allows you to pass more complex
information then just signal "I'm finished" using
Msg parameters (look at the SendMessage help in Win32
API) if you need to. It's not neccessary in your
example, but this is pretty usefull concept to
understand in communication between DLL and main App.
1) In DLL:
*****************
1.1) Add:
const
UM_PRINT = WM_USER+1; // Custom message ID
var
MainFormHandle: HWND; // Global var stores MainFormHandle
(...)
1.2)
Assume your DLL print procedure is called Print.
Add additional argument to this procedure like this:
procedure Print(AHandle: HWND);
begin
// Store handle of the MainForm widow:
MainFormHandle:=AHandle;
//... rest of your code (deal with the printing)...
end;
So, when you call print from your main form, you'll
send its handle to DLL via Print() procedure. There
it's stored in global var for later reuse.
1.3)
When the printing is finished, and you want to notify
the MainForm obout this, just send it message like this:
// Inform MainForm that printing is finished:
SendMessage(MainFormHandle
2) In EXE (MainForm):
**************************
2.1) Add custom message handler declaration like this:
const
UM_PRINT = WM_USER+1; // Custom message ID (same as in DLL)
Type
TForm1 = class(TForm)
...
procedure SetPrinted(var Msg: TMessage); message UM_PRINT;
...
end;
2.2) In definition do whatever you like:
procedure TForm1.SetPrinted(var Msg: TMessage);
// Called from DLL using SendMessage
begin
Caption:='Printing finished!';
end;
--------------------------
This method also allows you to pass more complex
information then just signal "I'm finished" using
Msg parameters (look at the SendMessage help in Win32
API) if you need to. It's not neccessary in your
example, but this is pretty usefull concept to
understand in communication between DLL and main App.
To set cbPrinted just replace line:
Caption:='Printing finished!';
with:
cbPrinted.Checked:=TRUE;
Caption:='Printing finished!';
with:
cbPrinted.Checked:=TRUE;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THanks! Woundewrfoul!!!
Solution a)
----------------
1. Send MainForm.Handle as additional argument to your DLL
printing procedure
2. Send custom message back from the DLL to the MainForm
when you want to inform your MainForm that printing is
done.
3. Set MainForm.Printed := True inside event handler for
this message
Solution b)
-----------------
1. Write and export DLL function IsPrinted()
2. Use TTimer in MainForm and periodically call IsPrinted()