Solved

WinProc & Delphi2

Posted on 1997-05-23
3
564 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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I solved the problem myself while waiting for the answer.  Sperlings answer was correct.  Thanks.

Jeff Jolie
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now