?
Solved

Pointer to a function or something.

Posted on 2002-06-28
10
Medium Priority
?
169 Views
Last Modified: 2010-04-04
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?



0
Comment
Question by:wqclatre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 7

Expert Comment

by:Cynna
ID: 7115777
wqclatre,

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()
0
 
LVL 2

Expert Comment

by:aubs
ID: 7115826
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(@FPrinted);


In the dll declare the function parameter as a Pointer:

  procedure myPrintDllFunction(aPrinted: 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

0
 
LVL 2

Author Comment

by:wqclatre
ID: 7115940
Cynna

you don't think you could give me an example of a)
(I don't know how to use handles
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:wqclatre
ID: 7115986
when I try to do:

Printed^:= True;


ist says: operator is not applicable to this operand type;

(I have   Printed : Pointer;)
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7116027
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(@FPrinted, @cbPrinted.checked);
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7116038
Sorry I mean

cbPrinted : TCheckBox.

0
 
LVL 7

Expert Comment

by:Cynna
ID: 7116042
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.
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7116045
To set cbPrinted just replace line:

   Caption:='Printing finished!';

with:

   cbPrinted.Checked:=TRUE;
0
 
LVL 7

Accepted Solution

by:
Cynna earned 400 total points
ID: 7116052
Sorry, I forgot to tell you how to pass
main form handle to DLL.

Assume you called your print procedure from MainForm like this:

procedure TForm1.Button11Click(Sender: TObject);
// (old way)
begin
  // Call DLL printing procedure:
  Print;
end;

If you change Print() procedure like I showed you in 1.2),
then you should change your calling code like this:

procedure TForm1.Button11Click(Sender: TObject);
// (new way)
begin
  // Call DLL printing procedure, and pass it MainForm handle:
  Print(Form1.Handle);
end;
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7116071
THanks! Woundewrfoul!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question