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
Solved

WinProc & Delphi2

Posted on 1997-05-23
3
568 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
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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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