I am trying to get Delphi to call the SetFocus Windows API function but it apparently wants to
treat SetFocus as a method of my form rather than the Windows API function. The following code
results in a compile Error 85: ";" expected with the cursor pointing right after the SetFocus
function but before the (HadFocus) parameter list.
HadFocus := GetFocus;
Show;
PaintBox1.Canvas.TextOut(0, 0, SubMsgText);
SetFocus(HadFocus);
You will notice that the GetFocus API function call works and I suspect this is because there is
no Delphi Object Pascal method for Forms called "GetFocus".
My question is how does one tell Delphi to use the Windows API function instead of a similarly
named object method?
--
Since the function you want to use is in the WinProces Unit ,
do this:
winprocs.setfocus(HadFocus);
Hope this helps.
Arno Theron
PC-Estim/PROJEVAL(7D2C)
Tel(012) 311-1824
082-569-2532
Fax(012) 311-4438
eMAIL : THER...@TELKOM19.TELKOM.CO.ZA
>Greetings,
>I am trying to get Delphi to call the SetFocus Windows API function but it apparently wants to
>treat SetFocus as a method of my form rather than the Windows API function. The following code
>results in a compile Error 85: ";" expected with the cursor pointing right after the SetFocus
>function but before the (HadFocus) parameter list.
> HadFocus := GetFocus;
> Show;
> PaintBox1.Canvas.TextOut(0, 0, SubMsgText);
> SetFocus(HadFocus);
>You will notice that the GetFocus API function call works and I suspect this is because there is
>no Delphi Object Pascal method for Forms called "GetFocus".
>My question is how does one tell Delphi to use the Windows API function instead of a similarly
>named object method?
You use WinProcs.SetFocus(HadFocus);
--
Isaac Hepworth ijh...@cam.ac.uk
Corpus Christi College, Cambridge University, UK
Thanks much for the quick response! Works great!
Craig.
>Greetings,
>I am trying to get Delphi to call the SetFocus Windows API function but it apparently wants to
>treat SetFocus as a method of my form rather than the Windows API function. The following code
>results in a compile Error 85: ";" expected with the cursor pointing right after the SetFocus
>function but before the (HadFocus) parameter list.
> HadFocus := GetFocus;
> Show;
> PaintBox1.Canvas.TextOut(0, 0, SubMsgText);
> SetFocus(HadFocus);
>You will notice that the GetFocus API function call works and I suspect this is because there is
>no Delphi Object Pascal method for Forms called "GetFocus".
>My question is how does one tell Delphi to use the Windows API function instead of a similarly
>named object method?
If you want to access an ambiguously named thing from a specific
unit, do it explicitly, e.g., SpecificUnit.AmbiguouslyNamedThing,
or in this case perhaps Windows.SetFocus(HadFocus); That way it
can't accidentally be hidden by something in the immediate scope,
and won't be affected by shuffling uses-order.
Regards,
Bengt Richter
Hello,
Maybe the following will help?
var
HadFocus : string;
{Assuming that some object has the focus,}
begin
HadFocus := Object.Name; //Save the name property
Show; //Show whatever it is you want to show
PaintBox1.Canvas.TextOut(0, 0, SubMsgText); //Do something
with Object as TObject do //Typecast the HadFocus variable you saved
SetFocus; //SetFocus back to it.
end;
I don't know about actually referencing the Win API SetFocus function unless
maybe it uses some unit that is not in your uses list? (ie., adding to uses
would let the compiler know it is not meant to be a form method)
Hope it helps
Chris
unit MyUnit;// for D2
interface
type
DWORD = Integer; //from windows.pas
BOOL = LongBool;
const
kernel32 = 'kernel32.dll';
function MyBeep(dwFreq, dwDuration:Dword):Bool; stdcall;
// dwFreq:sound frequency, in hertz
// dwDuration:sound duration, in milliseconds
// works in NT as expected, defaults to standard beep in Win95
implementation
function MyBeep; external kernel32 name 'Beep';
end.
beep is defined in SysUtils.pas as:
procedure Beep;
begin
MessageBeep(0);
end;
and defined in windows.pas:
interface:function Beep(dwFreq, dwDuration: DWORD): BOOL; stdcall;
implementation:function Beep; external kernel32 name 'Beep';
(a minor 'bug').
--
Paul, (Fri, 9 May 96, 11:20 EST)
SoftStuff, Croydon, Victoria, Australia, 3136
pa...@linuxserver.pccity.com.au
On Friday, May 10, 1996, Chris wrote...
> HadFocus := GetFocus;
> Show;
> PaintBox1.Canvas.TextOut(0, 0, SubMsgText);
> SetFocus(HadFocus);
>You will notice that the GetFocus API function call works and I suspect this is because there is
>no Delphi Object Pascal method for Forms called "GetFocus".
>My question is how does one tell Delphi to use the Windows API function instead of a similarly
>named object method?
Just change SetFocus(HadFocus); to Windows.SetFocus(HadFocus); for
delphi 2, or for Delphi 1, WinProcs.SetFocus(HadFocus); Easy eh? =)
I have tried everything I can think of, and perhaps I have no clue, or I'm
missing something simple. However, I am trying to click a button on a
child form of another app from Delphi 2.0 running Win 95. I have
successfully obtained the handle for all Windows, The main frame, the MDI
Client, and all childs. But when I send the external app messages from my
program, I get no visual response (ie, the button does not do its thing.)
Please help, here is the code I'm working with. I have no declarations
other than the standard declarations when selecting the "OnKeyUp" event. I
would be happy to use Delphi "TKey" conventions if I knew how.
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If ((Shift = [ssCtrl]) and (Key = 13)) then
Begin
testing := 0;
CurrentWindow := GetActiveWindow();
MyWindow := FindWindow('SomeFrame', 'SomeName');
MyMDI := FindWindowEx(MyWindow, testing, 'MDIClient' + #0, '' + #0);
MyChild := FindWindowEx(MyMDI, testing, 'My Child' + #0, 'SomeName' +
#0);
HiddenComboBox := FindWindow('ComboLBox', '');
Button := FindWindowEx(MyChild, Testing, 'SomeName' + #0, '' + #0);
Windows.SendMessage(MyChild, WM_KEYDOWN, VK_RETURN, 0);
Windows.SendMessage(MyChild, WM_KEYUP, VK_RETURN, 0);
Windows.SetForegroundWindow(MyChild)
end;
end;
PS, it appears that switching Focus between my program and the target
external application has each application running their code when they
have focus exclusively. If someone could give me an example of successful
code with a SID external app I believe I can adapt.
Thanks for your time ;-)
Dana Kirkpatrick
Not a bug at all.
Why go through all that when all you have to do is call it with the unit name
specified, i.e. windows.beep;?