在D2009下可用的CnDock组件
我的一个软件使用了CnPack中的停靠组件,也就是之前的DockPresident组件,但转到Delphi2009后,这套组件出现了一个问题,就是从文件或注册表中读取停靠信息时会出现错误(两个月前一个帖子提到这个问题)。最近仔细研究了一下还是Delphi2009对字符串处理默认是UnicodeString出现的问题。需要修改以下三个文件
CnDockFormControl.pas,CnDockSupportProc.pas,CnDockTree.pas
CnDockSupportProc.pas重写下面两个函数
function Cn_StreamDataToString(Stream: TStream): string;
var b: Byte;
begin
Result := '';
Stream.Position := 0;
while Stream.Position < Stream.Size do
begin
Stream.Read(b, Sizeof(b));
Result := Result + IntToHex(b, 2);
end;
end;
procedure Cn_StringToStreamData(Stream: TStream; Data: string);
var
i: Integer;
b: Byte;
begin
i := 1;
while i < Length(Data) do
begin
b := StrToInt('$' + Copy(Data, i, 2));
Stream.Write(b, Sizeof(b));
Inc(i, 2);
end;
end;
CnDockFormControl.pas的TCnTabPageControl.LoadFromStream过程一处修改
Stream.Read(Pointer(ControlName)^, NameLen {$IFDEF DELPHI2009_UP} * SizeOf(Char) {$ENDIF});
TCnTabPageControl.SaveToStream
if NameLen > 0 then Stream.Write(Pointer(ControlName)^, NameLen {$IFDEF DELPHI2009_UP} * SizeOf(Char) {$ENDIF});
CnDockTree.pas中
procedure TCnDockTree.WriteControlName(Stream: TStream; ControlName: string);
var
NameLen: Integer;
begin
NameLen := Length(ControlName);
Stream.Write(NameLen, SizeOf(NameLen));
if NameLen > 0 then Stream.Write(Pointer(ControlName)^, NameLen {$IFDEF DELPHI2009_UP} * SizeOf(Char) {$ENDIF});
end;
procedure TCnDockTree.ReadControlName(Stream: TStream;
var ControlName: string);
var
Size: Integer;
begin
ControlName := '';
Size := 0;
Stream.Read(Size, SizeOf(Size));
if Size > 0 then
begin
SetLength(ControlName, Size);
Stream.Read(Pointer(ControlName)^, Size {$IFDEF DELPHI2009_UP} * SizeOf(Char) {$ENDIF});
end;
end;
Attachment:
[修改后的三个文件]
停靠控件修改.rar (2008-11-18 10:47, 57.15 K)
Download count 483
|