好友
阅读权限40
听众
最后登录1970-1-1
|
费话说完,下面举例。
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus;type TMenuNotifyEvent = procedure(Sender: TMenuItem) of object; TForm1 = class(TForm) MainMenu1: TMainMenu; N1: TMenuItem; procedure AddMenuText(MenuText, FileName: string); procedure MenuClick(Sender: TMenuItem); procedure FormCreate(Sender: TObject); private { Private declarations } public FileName: string; end;var Form1: TForm1; NewMenuItem: TMenuItem;implementation{$R *.dfm}procedure TForm1.AddMenuText(MenuText, FileName: string);var EventName: TMenuNotifyEvent; NewMenuItem: TMenuItem;begin NewMenuItem := TMenuItem.Create(self); NewMenuItem.Caption := MenuText; NewMenuItem.Tag := Integer(PChar(FileName)); EventName := MenuClick; NewMenuItem.OnClick := TNotifyEvent(EventName); MainMenu1.Items[MainMenu1.Items.Count - 1].Add(NewMenuItem);end;procedure TForm1.MenuClick(Sender: TMenuItem);var s: AnsiString;begin s := AnsiString(Sender.Tag); WinExec(PAnsiChar(s), sw_normal);end;procedure TForm1.FormCreate(Sender: TObject);var sFile, sLine: TStrings; <========比如这里吧,把sFile 改成 文件名,下面的自动变化。 r, c: Integer; list: TStringlist;begin sFile := TStringList.Create; sFile.LoadFromFile('X:\test.txt'); sLine := TStringList.Create; for r := 0 to sFile.Count - 1 do begin ShowMessage(sFile[r]); //得到每行内容 sLine.CommaText := sFile[r]; for c := 0 to sLine.Count - 1 do begin list := TStringlist.Create; list.Delimiter := '='; //用=来分割 list.DelimitedText := (sFile[r]);// AddMenuText(list.Strings[0], list.Strings[1]); ShowMessage(list.Strings[0] + #13#10 + list.Strings[1]); //得到的每行的数组0和数组1内容(也就是=前后的部分) end; end; sLine.Free; sFile.Free;end;end. |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|