Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2003.05.01;
Download: [xml.tar.bz2];

Down

How to attach a procedure to a function Find similar branches


Лесник   (2003-04-17 23:55) [0]

Hi connoisseurs. I faced the following problem: It is necessary for me that the standard InputtBox, when entered in the Edit field, handle the OnKeyPress event and allow me to enter only numbers. I created my own unit in which I rewrote the procedure (from Dialogs.pas) InputBox and InputQuery. Everything works until I try to connect the EditKeyPress procedure after creating Edit.
Example code:

procedure EditKeyPress (Sender: TObject; var Key: Char);
begin
if not (Key in ["0" .. "9") then key: = # 0;
end;

function InputQueryN (const ACaption, APrompt: string;
var Value: string): Boolean;
...........
Edit: = TEdit.Create (Form);
with Edit do
begin
Parent: = Form;
Left: = Prompt.Left;
Top: = Prompt.Top + Prompt.Height + 5;
Width: = MulDiv (164, DialogUnits.X, 4);
MaxLength: = 255;
Text: = Value;
SelectAll;
OnKeyPress: = EditKeyPress; // error here
end;
.............
What is wrong here to help sort out.
Thank you.



Лесник   (2003-04-17 23:57) [1]

I apologize for a typo
procedure EditKeyPress (Sender: TObject; var Key: Char); begin if not (Key in ["0" .. "9"]) then key: = # 0; end;



DJ_Sedoy   (2003-04-18 05:18) [2]

As I understand it, the event handler must be an object method, and not just a procedure.



Palladin   (2003-04-18 07:07) [3]

type TKeyPressEvent = procedure (Sender: TObject; var Key: Char) of object;



malkolinge   (2003-04-18 13:07) [4]

Component code in the studio. Particularly interesting event dispatcher



Лесник   (2003-04-18 18:26) [5]

Anyway error
[Error] MyDialogs.pas (79): Incompatible types: "method pointer and regular procedure"



VAleksey   (2003-04-18 18:28) [6]

Deliver the handler's procedure description to the module.



Лесник   (2003-04-18 18:52) [7]

if i write
OnKeyPress (Form, EditKeyPress);
getting an error
[Error] MyDialogs.pas (79):



Юрий Федоров   (2003-04-18 19:47) [8]

This option
Type
TMyObject = class
procedure EditKeyPress (Sender: TObject; var Key: Char);

end; {class TMyObject}
....
var Obj: TMyObject;
....
function InputQueryN
.
OnKeyPress: = Obj.EditKeyPress;
Obj also need to create



Лесник   (2003-04-19 00:20) [9]

Thank you Yuri Fedorov ©
finally it turned out
Type TMyObject = class procedure EditKeyPress (Sender: TObject; var Key: Char); end; procedure TMyObject.EditKeyPress (Sender: TObject; var Key: Char); begin If not (Key in ["0" .. "9", Decimalseparator]) then Key: = # 0; end; ... function InputQueryN (const ACaption, APrompt: string; var Value: string): Boolean; var obj: TMyObject; .... Edit: = TEdit.Create (Form); with Edit do begin Parent: = Form; Left: = Prompt.Left; Top: = Prompt.Top + Prompt.Height + 5; Width: = MulDiv (164, DialogUnits.X, 4); MaxLength: = 255; Font.Color: = clNavy; Text: = Value; SelectAll; OnKeyPress: = Obj.EditKeyPress; end; ...
true issued
[Warning] MyDialogs.pas (92): Variable "Obj" might not have been initialized
but it works as it should.



Лесник   (2003-04-19 00:49) [10]

I was also advised
With Edit Do SetWindowLong (Handle, GWL_STYLE, GetWindowLong (Handle, GWL_STYLE) or ES_NUMBER);
also works but without decimal separator



LEON   (2003-04-19 20:07) [11]

to remove the warning after the run, write obj: = nil



Pages: 1 whole branch

Forum: "Main";
Current archive: 2003.05.01;
Download: [xml.tar.bz2];

Top





Memory: 0.58 MB
Time: 0.026 c
14-722
lirien
2003-04-13 11:45
2003.05.01
c ++ in Delphi7


3-439
Sanya
2003-04-13 18:54
2003.05.01
Help move the record


1-577
unknown
2003-04-18 13:40
2003.05.01
record -> file


1-604
Alex-21
2003-04-18 21:27
2003.05.01
File path


6-667
Ga3
2003-03-06 03:51
2003.05.01
browser properties





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic Indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish Thai turkish Ukrainian urdu Vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish