22-06-2016, 11:50 AM
السلام عليكم
كنت بحاجة الى هذا الكود واححبت ان اشارككم فيه ، لمن عنده طريقة افضل الرجاء الرد ومشكورين الاخوة
كنت بحاجة الى هذا الكود واححبت ان اشارككم فيه ، لمن عنده طريقة افضل الرجاء الرد ومشكورين الاخوة
كود :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus;
type
TForm1 = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
OpenDialog1: TOpenDialog;
Label3: TLabel;
Label4: TLabel;
PopupMenu1: TPopupMenu;
j1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure LoadTextFileToPopup (Popup:TPopupMenu;TextFileName:String;uEvent:TNotifyEvent);
procedure Myclick(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MyClick(Sender: TObject);
begin
Edit1.Text := (sender as TMenuItem).Caption;
end;
procedure Tform1.LoadTextFileToPopup (Popup:TPopupMenu;TextFileName:String;uEvent:TNotifyEvent);
var lst : TStringlist; i : integer; item: TmenuItem;
BEGIN
Lst := TStringlist.Create;
lst.LoadFromFile(TextFileName);
Popup.Items.Clear;
for i:=0 to lst.Count-1 do
begin
item :=TMenuItem.Create(nil);
Item.caption := lst.Strings[i];
item.OnClick := uEvent;
Popup.Items.Add(item);
end;
lst.Sorted := true;
lst.Sort;
END;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
if Not FileExists(OpenDialog1.fileName) then
showmessage('fiel not found .. ')
else
begin
LoadTextFileToPopup( PopupMenu1,OpenDialog1.FileName,Myclick);
label4.Caption := OpenDialog1.FileName;
end;
end;
end.