使用关联文件的方法
代码如下,共两个单元:
unit UnitFormWithPara;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses UnitAddRelation;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
strFileName:string;
begin
if paramcount>0 then
begin
strFileName:=paramstr(1);
self.Memo1.Lines.LoadFromFile(strFileName);
self.Caption:=strFileName;
end
else
begin
AddRelation('.sos','SOS File','ZZN',Application.ExeName);
end;
end;
end.
unit UnitAddRelation;
interface
uses
Registry, Windows;
function AddRelation(FileExtName,FileType, ContentType, ExeName:string):boolean;
implementation
function AddRelation(FileExtName,FileType, ContentType, ExeName:string):boolean;
var
Reg:TRegistry;
ExecName: String;
begin
ExecName:= ExeName + ' %1';
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_CLASSES_ROOT;
Reg.OpenKey(FileExtName,true);
Reg.WriteString('',FileType);
Reg.WriteString('Content Type',ContentType);
Reg.OpenKey('shell/open/command', True);
Reg.WriteString('',Execname);
reg.CloseKey;
result:=true;
finally
reg.Free;
end;
end;
end.