T
txiuq
Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个组件:
type
TResItem = class(TComponent)
private
{ Private Declarations }
FResTypeStr: string;
FresNameStr: string;
FSize: Integer;
FRawData: Pointer;
FResType: PChar;
FItems: TresItem;
FOffset: integer;
FResName: PChar;
protected
{ Protected Declarations }
public
{ Public Declarations }
constructor Create(AOwner: TComponent;H:THandle;Rtypechar;RNamechar;langid:word);
destructor Destroy; override;
property Size: Integer read FSize;
property Offset: Integer read FOffset;
property RawData: Pointer read FRawData;
property ResName: Pchar read FResName;
published
{ Published Declarations }
end;
TResList = class(TComponent)
private
{ Private Declarations }
FHandle: THandle;
FLangId: Word;
FResType: PChar;
Flist:Tlist;
protected
{ Protected Declarations }
procedure Loaded; override;
function GetItems(Index: Integer): TResItem;
function GetCount: Integer;
function GetResTypeStr: string;
public
{ Public Declarations }
constructor Create(AOwner: TComponent;H:THandle;Rtypechar;langid:word);
destructor Destroy; override;
property Items[Index: Integer]: TResItem read GetItems ;
property Handle: Thandle read FHandle;
property Count: Integer read GetCount ;
property LangId: Word read FLangId;
property ResType: PChar read FResType;
property ResTypeStr: string read GetResTypeStr ;
published
{ Published Declarations }
end;
implementation
constructor TResItem.Create(AOwner: TComponent;H:THandle;Rtypechar;RNamechar;langid:word);
Var
Resinfo,hres:THandle;
begin
inherited Create(AOwner);
FResType:=Rtype;
FResName:=Rname;
resinfo:=FindResourceex(H,RType, RName,LangId);
hres:=LoadResource(H, ResInfo);
FRawData:=LockResource(hres);
Foffset:=integer(Hres)-H;
Fsize:=sizeofresource(H,resinfo);
{Add any other initialization code here}
end;{Create}
function TResList.GetItems(Index: Integer): TResItem;
begin
Result := FList[Index];
end;{GetItems}
function TResList.GetCount: Integer;
begin
Result := FList.Count;
end;{GetCount}
constructor TResList.Create(AOwner: TComponent;H:THandle;Rtypechar;langid:word);
function EnumResProc(hMod: THandle; Restypechar;ResName: PChar;parm:integer): Boolean; stdcall;
Var
Fitem:TresItem;
begin
Fitem:=Tresitem.create(self,Hmod,ResType,ResName,FlangId);------1
Flist.Add(Fitem);-----2
result:=true;---------3
end;
begin
inherited Create(AOwner);
Fhandle:=H;
FresType:=Rtype;
FLangId:=Langid;
FList:=Tlist.Create;
EnumResourceNames(Fhandle, Frestype, @EnumResProc,integer(self));
{Add any other initialization code here}
end;{Create}
在主程序中使用如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
Rlist:Treslist;
hTemp:THandle;
begin
if opendlg.Execute then
begin
hTemp := LoadLibraryEx (PChar(opendlg.filename), 0, Load_Library_As_DataFile);
if hTemp <> 0 then begin ----------------4
rlist:=Treslist.Create(self,htemp,rt_rcdata,2048);
for I:=0 to Rlist.count-1 do
begin
memo1.lines.Add(string(rlist.Items.ResName));
end;
rlist.Free;
end;
end;
END;
程序中rlist.count始终为0,跟踪到位置1处便不能再跟踪了,并且程序立即跳到4处.
2,3语句好象根本未执行.不知我哪些语句有问题,谢谢你的帮助
编程环境(delphic/s4.0- update3);
type
TResItem = class(TComponent)
private
{ Private Declarations }
FResTypeStr: string;
FresNameStr: string;
FSize: Integer;
FRawData: Pointer;
FResType: PChar;
FItems: TresItem;
FOffset: integer;
FResName: PChar;
protected
{ Protected Declarations }
public
{ Public Declarations }
constructor Create(AOwner: TComponent;H:THandle;Rtypechar;RNamechar;langid:word);
destructor Destroy; override;
property Size: Integer read FSize;
property Offset: Integer read FOffset;
property RawData: Pointer read FRawData;
property ResName: Pchar read FResName;
published
{ Published Declarations }
end;
TResList = class(TComponent)
private
{ Private Declarations }
FHandle: THandle;
FLangId: Word;
FResType: PChar;
Flist:Tlist;
protected
{ Protected Declarations }
procedure Loaded; override;
function GetItems(Index: Integer): TResItem;
function GetCount: Integer;
function GetResTypeStr: string;
public
{ Public Declarations }
constructor Create(AOwner: TComponent;H:THandle;Rtypechar;langid:word);
destructor Destroy; override;
property Items[Index: Integer]: TResItem read GetItems ;
property Handle: Thandle read FHandle;
property Count: Integer read GetCount ;
property LangId: Word read FLangId;
property ResType: PChar read FResType;
property ResTypeStr: string read GetResTypeStr ;
published
{ Published Declarations }
end;
implementation
constructor TResItem.Create(AOwner: TComponent;H:THandle;Rtypechar;RNamechar;langid:word);
Var
Resinfo,hres:THandle;
begin
inherited Create(AOwner);
FResType:=Rtype;
FResName:=Rname;
resinfo:=FindResourceex(H,RType, RName,LangId);
hres:=LoadResource(H, ResInfo);
FRawData:=LockResource(hres);
Foffset:=integer(Hres)-H;
Fsize:=sizeofresource(H,resinfo);
{Add any other initialization code here}
end;{Create}
function TResList.GetItems(Index: Integer): TResItem;
begin
Result := FList[Index];
end;{GetItems}
function TResList.GetCount: Integer;
begin
Result := FList.Count;
end;{GetCount}
constructor TResList.Create(AOwner: TComponent;H:THandle;Rtypechar;langid:word);
function EnumResProc(hMod: THandle; Restypechar;ResName: PChar;parm:integer): Boolean; stdcall;
Var
Fitem:TresItem;
begin
Fitem:=Tresitem.create(self,Hmod,ResType,ResName,FlangId);------1
Flist.Add(Fitem);-----2
result:=true;---------3
end;
begin
inherited Create(AOwner);
Fhandle:=H;
FresType:=Rtype;
FLangId:=Langid;
FList:=Tlist.Create;
EnumResourceNames(Fhandle, Frestype, @EnumResProc,integer(self));
{Add any other initialization code here}
end;{Create}
在主程序中使用如下代码:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
Rlist:Treslist;
hTemp:THandle;
begin
if opendlg.Execute then
begin
hTemp := LoadLibraryEx (PChar(opendlg.filename), 0, Load_Library_As_DataFile);
if hTemp <> 0 then begin ----------------4
rlist:=Treslist.Create(self,htemp,rt_rcdata,2048);
for I:=0 to Rlist.count-1 do
begin
memo1.lines.Add(string(rlist.Items.ResName));
end;
rlist.Free;
end;
end;
END;
程序中rlist.count始终为0,跟踪到位置1处便不能再跟踪了,并且程序立即跳到4处.
2,3语句好象根本未执行.不知我哪些语句有问题,谢谢你的帮助
编程环境(delphic/s4.0- update3);