Solved

WinProc & Delphi2

Posted on 1997-05-23
3
569 Views
Last Modified: 2010-04-04
I hope someone can help me....

The following are code snipits from an application I am trying
to get running.  I've run it using straight windows API calls but
now need to run it from a Delphi2 application. The function
TfrmMain.InitDigitizingArm starts a backgound
process that sends messages to the function WindowProc in straight
windows API programming.  What is the equivalent in Delphi? In Delphi2
will it send the data to the
frmMain.WMCommand?  Is my application.handle correct (frmMain.Handle vs
Application.Handle)?  I'm sure I've overlooked something simple.
Any help is surely appreciated.  Thanks in advance.

Jeff Jolie
Shaken, not stirred.


        public
         { Public declarations }
    Password : string ;
    procedure WMCommand(var Message:TMessage); message wm_Command;


procedure TfrmMain.WMCommand(var Message: TMessage);
var
  a : parm_rec;
begin
   inherited;
   New(a);

   if Message.WParam = armMessageVal then
   begin
      a := pArmGetArmRec;// @LParam;
      // more processing here
   end;
end;

/// This function called during frmMain create

function TfrmMain.InitDigitizingArm : boolean;
begin
   armMessageVal := RegisterWindowMessage(ARM_MESSAGE);

   hLib := LoadLibrary('Armdll32.dll');
   pArmStart := GetProcAddress(hLib,'ArmStart');
   pArmConnect := GetProcAddress(hLib,'ArmConnect');
   pArmSetBckgUpdate := GetProcAddress(hLib,'ArmSetBckgUpdate');
   pArmGetArmRec := GetProcAddress(hLib,'ArmGetArmRec');

   ...this handle is key....
   status := pArmStart(frmMain.Handle); // tried Application.Handle with
no luck

   Result := True;
   if( status <> ARM_SUCCESS ) then
   begin
      MessageBox(0,'Can not start ArmStart','ArmStart Error',mb_ok);
      Result := False;
      Exit;
   end
   else
   begin
      status := pArmConnect(2,9600);
      if ( status = ARM_SUCCESS ) then
      begin
         status := pArmSetBckgUpdate(ARM_3DOF);  // this should send
messages to frmMain.WMCommand, but doesn't
         if ( status <> ARM_SUCCESS ) then
         begin
            MessageBox(0,'Can not set bkgnd update.','BkgndUpdate
Error',mb_ok);
            Result := False;
            Exit;
         end;
      end
      else
      begin
         MessageBox(0,'Arm Connect Error.','ArmConnect Error',mb_ok);
         Result := False;
         Exit;
      end;

   end;
end;
0
Comment
Question by:neame
[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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336547
Why are you using WM_COMMAND?

As far as I can see from your code, you need to respond to the message ID returned by RegisterWindowMessage. This cannot be done using the message directive in the handler declaration, as this expects a constant, like e.g. WM_COMMAND.

The solution to this is simply to override the main forms WndProc, which was introduced in ancestor TControl, and handle the message there.

.
.
private
  procedure WndProc (var Message : TMessage); override;
.
.

procedure TFrmMain.WndProc (var Message : TMessage);
begin
  if Message.Msg = armMessageVal then begin
    // Handle the message here
  end else inherited WndProc(Message);
end;

Regards,

Erik.
0
 
LVL 3

Expert Comment

by:sperling
ID: 1336548
BTW.

You should use TFrmMain.Handle. If you use Application.Handle, you need to obtain the message using Application.HookMainWindow.

Regards,

Erik.
0
 

Author Comment

by:neame
ID: 1336549
I solved the problem myself while waiting for the answer.  Sperlings answer was correct.  Thanks.

Jeff Jolie
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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