Autor Beitrag
Moonbiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Do 28.12.06 13:04 
Hallo,

bin dabei häufig verwendete proceduren in eine Unit auszulagern, und dabei ist es mir nicht gelungen ONKEYPRESS mit der EditKeypress aus einer anderen Unit zu verwenden.

Hier mal der Code der Unit, diese wird per USES mit eingebunden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
unit klheUnit;

interface

uses
  Windows, Forms;

procedure Wait(time: double);
procedure EditKeyPress(Sender: TObject; var Key: Char);

implementation

procedure Wait(time: double);
var Start: Integer;
begin
  Start:=GetTickCount;
  while GetTickCount-Start <= time do Application.ProcessMessages;
end;

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

end.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 28.12.06 13:07 
Wir bräuchten der Source der anderen Unit, da wo sich das nicht funktionierende Edit befindet. Hast du dem Edit die Prozedur zugewiesen?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Do 28.12.06 14:37 
Das geht deshalb nicht, weil OnKeyPress eine procedure of Object ist, also eine Methode einer Instanz. Machst du dir eine Klasse, die diese Methode hat und erzeugst eine Instanz davon, kannst du die Methode der Instanz jedem TEdit zuweisen.

Viele Grüße
Alex
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 28.12.06 19:38 
Außerdem könntest du das auch so machen, dass du die Methode in deiner separaten Unit direkt im OnKeyPress aufrufst.
So nach dem Motto: Methode FilterNonNumbers mit denselben Parametern oder so in der separaten Unit und dann in OnKeyPress: FilterNonNumbers(Sender, Key);
Moonbiker Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37



BeitragVerfasst: Fr 29.12.06 09:25 
Vielen Dank euch!

wie eben von jaenicke beschrieben hatte ich es als Notlösung auch shcon, das andere werde ich mal probieren.

Danke und guten Rutsch!