Продолжнение "Вызывает антирес и такой ишо разрез" Как можно осуществить событие для динамически созданного компонента? Проблема в том, что программа модульная и "процедура не описана как метод формы".
procedure MyOnClick(Sender: TObject); begin form1.Label1.Caption:=inttostr(form1.MainMenu1.Items.IndexOf(sender as TMenuItem)); end;
procedure CreateSubMenu(MainMenu: TMainMenu; p: TP); var i,j: integer; k: longint; N: TMenuItem; begin k:=3; //... SetLength(MenuItemArray, 2, k); for j:=0 to k-1 do for i:=0 to 1 do begin N:=TMenuItem.Create(MainMenu); n.Caption:=inttostr(i)+inttostr(j); n.OnClick:=MyOnClick; //вот здесь пишет Incompatible types: 'method pointer and regular procedure' MainMenu.Items[i+1].items[1].Insert(j,n); MenuItemArray[i][j]:=n; end; end;
Сама программа: VstupInfo.rar ( 275.13 килобайт )
Кол-во скачиваний: 506
Все, конечно же, можно обойти, но так было бы чуть короче:
Код(Показать/Скрыть)
//...
procedure MyPathChange({Sender: TObject;}n: integer;var SourceVisual: TSourceVisual); var i: longint; begin for i:=3 to 5 do memo[i].Lines.Clear; if SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text) > -1 then begin FindWreckersOnline(Memo[n], source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Name); SourceVisual[n].Places.Caption := inttostr(source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Places); SourceVisual[n].Budget.Caption := inttostr(source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Budget); end; end;
procedure MyPathKeyPress({Sender: TObject;}n:integer; var Key: char;var SourceVisual: TSourceVisual); begin if (key = #13) then if SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text) > -1 then begin FindWreckersOnline(Memo[n], source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Name); SourceVisual[n].Places.Caption := inttostr(source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Places); SourceVisual[n].Budget.Caption := inttostr(source[SourceVisual[n].Path.Items.IndexOf(SourceVisual[n].Path.Text)].Budget); end else FindWreckersOnline(Memo[n], SourceVisual[n].Path.Text); end;
procedure TForm1.FormCreate(Sender: TObject); {var i: integer; M1, M2: TMethod; }begin //... { for i := 1 to 2 do begin M1.Code := @MyPathChange; M1.Data := SourceVisual[i].Path; SourceVisual[i].Path.OnChange := TNotifyEvent(M1); end; } //... end;
//А вот от этого в случае передачи параметров можно было бы отказаться
procedure TForm1.ComboBox1Change(Sender: TObject); begin MyPathChange(1,SourceVisual); end;
procedure TForm1.ComboBox2Change(Sender: TObject); begin MyPathChange(2,SourceVisual); end;
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char); begin MyPathKeyPress(1,Key,SourceVisual); end;
procedure TForm1.ComboBox2KeyPress(Sender: TObject; var Key: Char); begin MyPathKeyPress(2,Key,SourceVisual); end;
end.
Ну и сам проэкт VstupInfo.rar ( 284.58 килобайт )
Кол-во скачиваний: 394