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

Down

Determine the menu item number Find similar branches


T2   (2001-12-16 07:29) [0]

Programmatically create a menu. I push the names of the available disks into the popup menu (it is not known in advance how many there are). How to find out which menu item was selected, preferably in one processing procedure?



KilkennyCat   (2001-12-16 08:02) [1]

I do this:

I create a processing procedure for which I forward clicks from all points. type:

procedure TForm1.popClick (Sender: TObject);
begin
if sender = b then showmessage ("b"); // clicked item named b
if sender = a then showmessage ("a"); // clicked item named a
end;

Of course, with a large number of points you need to be indexed.



T2   (2001-12-16 08:59) [2]

Yes, but the names "a" and "b" are unknown before creation. These menu items are not available when
compilation and when trying to compare sender = a, the error "Undeclared identifier:" a. is thrown. Can the code be clearer?

procedure TMain.pu2Popup (Sender: TObject);
var s: tstringlist; i: byte; NewItem: TMenuItem; f: int64; d: string [1];
begin
pu2.Items.Clear; s: = tstringlist.create;
si.GetDriveList (s); for i: = 0 to s.Count-1 do begin
NewItem: = TMenuItem.Create (Self);
d: = copy (uppercase (s.strings [i]), 1,1);
f: = diskfree (ord (d [1]) - 64); If f = -1 then f: = 0;
NewItem.Caption: = "&" + d + ": (" + Inttostr (f) + "bytes)";
newitem.OnClick: = ddd;
imagelist1.getbitmap (0, newitem.Bitmap);
pu2.items.Add (NewItem);
end; s.free;
end;

procedure tmain.ddd (sender: tobject);
begin
if sender = c1 then showmessage ("Disk <C> select"); // So ?
end;

Is that all right?



KilkennyCat   (2001-12-16 09:07) [3]

um ... in my opinion, it is necessary to create NewItem.Name (for example, a)



Anatoly Podgoretsky   (2001-12-16 10:11) [4]

You have NewItem.Caption the second letter is the name of the drive, this is enough to identify



Dmitriy(new)   (2001-12-16 12:09) [5]

procedure tmain.ddd (sender: tobject); var d: string [1];
begin
d: = copy (TMenuItem (sender) .Caption, 2,1);
showmessage ("Disk <" + D + "> select");
// if sender = c1 then showmessage ("Disk <C> select"); // So ?
end;



Петрович   (2001-12-17 04:47) [6]

Or you can try using the Tag property!



GennadyS   (2001-12-17 08:45) [7]

I always used the TAG property in such cases. And depending on the number of points I knew exactly which click. (for all points a single processing procedure) In this procedure:

case (sender as TComponent) .tag of
1: // disk processing B
2: // - / - C
.



Pages: 1 whole branch

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

Top





Memory: 0.56 MB
Time: 0.028 c
1-22189
bestix
2001-12-14 19:54
2002.01.08
Metafiles


6-22298
karafuto
2001-10-11 14:00
2002.01.08
Why do you need TIdAntiFreeze (InDy)?


14-22357
Viktor Shcherbakov
2001-11-01 12:40
2002.01.08
Photo recovery


1-22206
T2
2001-12-16 07:11
2002.01.08
Align field


3-21954
strahov
2001-12-05 15:32
2002.01.08
Has anyone met a bug





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