Hello,
I'm working on Linux (Mint 22.1).
I want to create a dynamic pop-up menu using a small file containing the labels for each item to be created. The goal is to populate a Memo with the label of the selected item, adding the current date before it.
I managed to create it, and the display works fine, but I'm running into two problems:
1- During creation: I can't assign a procedure to the OnClick event. This is a standard procedure in the same source code.
MenuItem.OnClick := CtrlLigneVierge;
Error: Incompatible types: got "untyped" expected "<procedure variable type of procedure(TObject) of object;Register>"
2- Unable to retrieve the caption label (the date is correctly positioned)
Memo1.Lines[WLine] := ' - ' + FormatDateTime('dd/mm/yyyy',now) + ' '
+ PopupMenu2.Items[popupmenu2.MenuIndex];
Error: identifier idents no member "MenuIndex"
(Syntax that works with a combo box). I tried variations without success.
Currently, to execute this action, I have to use the memo's "OnMouseDown" event to execute the "CtrlLigneVierge" procedure.
Perhaps there is missing information to save when creating the popup menu? I haven't found any additional information.
FYI: The program currently works well, but with a popup menu updated via the menu editor. The downside is that every time there's a change to make to one or more labels, I have to modify the program and recompile it. Furthermore, several people use this program, and the labels may be different, depending on each user's usage.
My goal is to provide the ability to edit the file in the program via a small form with a dbgrid. Everyone will put whatever they want in it. The list will therefore contain what interests the user, and only what interests them, instead of having all the labels for all users.
var
Form1: TForm1;
WLigne : integer;
MenuItem : TMenuItem;
implementation
{$R *.lfm}
{ TForm1 }
// --------------------------------------------------------------------------
// FORME | Create
// --------------------------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
var
MenuItem : TMenuItem;
Wi : integer;
begin
if not dbf1.active then dbf1.open;
// initialise Items PopupMenu;
dbf1.first;
Wi := 0;
While not Dbf1.EOF do
begin
Wi := Wi + 1;
MenuItem := TMenuItem.Create(PopupMenu2);
{ Ajouter au PopupMenu }
MenuItem.Caption := Dbf1LIBELSUIVI.Value;
MenuItem.name := 'Menuitem' + IntToStr(Wi);;
MenuItem.OnClick := CtrlLigneVierge;
PopupMenu2.Items.Add(MenuItem);
dbf1.next;
end;
//Dbf1.Close;
end;
// --------------------------------------------------------------------------
// MEMO | Controle écrase ligne en cours
// --------------------------------------------------------------------------
procedure TForm1.CtrlLigneVierge;
begin
if (Memo1.Lines[WLigne] <> '') then
if MessageDlg('Ecraser le contenu de la ligne Mémo (Ligne ' + intToStr(Wligne + 1) + ') ?',
mtConfirmation, [mbYes, mbNo], 0, mbNo) = mrNo
then
Abort
else
// ItemIndex
Memo1.Lines[WLigne] := ' - ' + FormatDateTime('dd/mm/yyyy',now) + ' '
+ PopupMenu2.Items[popupmenu2.MenuIndex]; // compile pas (err)
end;