Recent

Author Topic: [SOLVED] Perform() function and Messages  (Read 9676 times)

muzzoman

  • Guest
[SOLVED] Perform() function and Messages
« on: June 09, 2009, 12:17:03 pm »
Hi all,
in a Lazarus Windows application I would like to change internal margin of a Tedit control; looking around the web I found that EM_SETMARGINS message does exactly the work I want.
But when I tried to use it into my code, like this:
Code: [Select]
 edit1.Perform(EM_SETMARGINS, 1,MAKELONG(15,0));
  edit1.Text:='MARGIN CHANGED';
nothing happens.

I used the Perform() function because Lazarus doesn't support the Delphi SendMessage func (so the wiki says).

My two simple questions are:

1) does Lazarus full supports Perform() function?
2) is there some mistake in the way I call Perform()?

Just for a test I tried same lines of code into Delphi 5 and everything works correctly.

I have Lazarus 0.9.26.3 version - SVN 18973 running on Win XP pro.

Any ideas?
Thanks in advance
« Last Edit: June 09, 2009, 06:40:08 pm by muzzoman »

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Perform() function and Mewssages
« Reply #1 on: June 09, 2009, 05:05:23 pm »
Add Windows unit
and use SendMessage

muzzoman

  • Guest
Re: Perform() function and Messages
« Reply #2 on: June 09, 2009, 06:38:03 pm »
Thanks Zaher, it works!
I'm pretty new to Lazarus and was confused by reading the Wiki about the not implementation of SendMessage and the way Lazarus manages win-messages.
Maybe wiki is not up-to-date about this argument, or maybe I couldn't find info on this.
These are the working code I wrote upon Zaher suggest, in case somebody has same doubt as me:
Code: [Select]
{Directives added to Interface/Uses section of my form }
//...
   LMessages, LCLIntf, Windows
//...

{Instructions (into a buttonOnClick procedure)}
//....
       SendMessage(edit1.handle,EM_SETMARGINS, 1,MAKELONG(15,0));
       edit1.text:='MARGIN CHANGED';
//....

Paul Ishenin

  • Sr. Member
  • ****
  • Posts: 274
Re: [SOLVED] Perform() function and Messages
« Reply #3 on: June 10, 2009, 03:35:26 am »
This code will work only on windows.

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: [SOLVED] Perform() function and Messages
« Reply #4 on: June 10, 2009, 07:29:41 am »
I think what Paul means is that although the Window API functions SendMessage and PostMessage can be simulated okay, for example:

function SendMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
var
  AWinControl : TWinControl;
begin
  Assert(hWnd <> 0, 'Window handle not assigned on entry to SendMessage');
  AWinControl := FindOwnerControl(hWnd);
  if AWinControl <> nil then
    Result := AWinControl.Perform(Msg, wParam, lParam);
end;

A message such as EM_SETMARGINS only makes sense on the win32 widgetset.

Thanks.

-Phil

muzzoman

  • Guest
Re: [SOLVED] Perform() function and Messages
« Reply #5 on: June 10, 2009, 08:55:33 am »
Hi,
I know that EM_SETMARGINS message (and all other) works only in Windows o.s.
I'm developing an application using Lazarus for Windows, but I am also a Linux user; my final goal is to make my application "platform independent"
To do this I isolated all the tasks that could be influenced by the operanting system in use and treat them as "black boxes", this is the reason for which I have to use messages in this particular piece of code.
Phil suggested also a emulated version of SendMessage(), I will try it (just for improve my Lazarus knowledgement) but what about the instruction AWinCOntrol.Perform(Msg, wParam, lParam)?
As I said above, all attempted to use Perform() function failed for me.

Greetings.

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: [SOLVED] Perform() function and Messages
« Reply #6 on: June 10, 2009, 01:15:03 pm »
Set the margin can be on Windows only not sure about other systems

SendMessage use the Handle of window/control, and as i think Lazarus in the future must  leave using Handles like as HWND and HDC, after few years surely.

for example
  InvalidateRect(aHandle : HWND; ARect : pRect; bErase : Boolean)
while it is must be (in my opinion)
  InvalidateRect(Control : TWinControl; ARect : Rect;  Erase : Boolean)

 

TinyPortal © 2005-2018