[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

WinProc & Delphi2

Posted on 1997-05-23
3
Medium Priority
?
577 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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