CnPack Forum


 
Subject: 在D2009下可用的CnDock组件
wqyfavor
灌水科科长
Rank: 3Rank: 3



UID 40865
Digest Posts 0
Credits 130
Posts 45
点点分 130
Reading Access 10
Registered 2008-9-2
Status Offline
Post at 2008-11-18 10:47  Profile | Blog | P.M. 
在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
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-11-18 11:08  Profile | Blog | P.M. 
感谢楼主的报告与修改,我们会检查一下合并入CVS的。
Top
wqyfavor
灌水科科长
Rank: 3Rank: 3



UID 40865
Digest Posts 0
Credits 130
Posts 45
点点分 130
Reading Access 10
Registered 2008-9-2
Status Offline
Post at 2008-11-18 11:29  Profile | Blog | P.M. 
突然想起来可以不用编译控制的,直接就是NameLen* SizeOf(Char) ,因为在Delphi2007之前,SizeOf(Char) 就是1.
Top
Passion (LiuXiao)
管理员
Rank: 9Rank: 9Rank: 9


UID 359
Digest Posts 19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
Post at 2008-11-18 11:34  Profile | Blog | P.M. 
嘿嘿对。我也是这么合并的。不过仍然很感谢。
Top
 




All times are GMT++8, the time now is 2024-11-22 13:26

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.008384 second(s), 8 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP