RealICQUtility.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. unit RealICQUtility;
  2. interface
  3. uses
  4. Classes, SysUtils;
  5. type
  6. TRealICQUtility = class
  7. private
  8. public
  9. class procedure ClearStringList(AStringList: TStringList);
  10. class procedure FreeStringList(AStringList: TStringList);
  11. class procedure FreeList(AList: TList); static;
  12. class function SplitString(const Source, Ch: string): TStringList;
  13. class function GetServerID(ALoginName: string): string;
  14. class function GetAndClearServerID(var ALoginName: string): string;
  15. class function ClearServerID(ALoginName: string): string; static;
  16. class function ClearCenterServerID(ALoginName: string): string; static;
  17. class function FullLoginName(ACenterServerID, AServerID, ALoginName: string): string; static;
  18. class function GetLocalUID(ACenterServerID, AServerID, ALoginName: string): string;
  19. class function GetGuid: string;
  20. end;
  21. implementation
  22. //procedure TRealICQUtility.AccessDropFiles(AControl: TWinControl);
  23. //const
  24. // WM_COPYGLOBALDATA = $0049;
  25. //var
  26. // DLL_Handle: Integer;
  27. // _ChangeWindowMessageFilter: T_ChangeWindowMessageFilter;
  28. //begin
  29. // try
  30. // DLL_Handle := LoadLibrary('user32.dll');
  31. // if DLL_Handle <> 0 then
  32. // begin
  33. // try
  34. // _ChangeWindowMessageFilter := GetProcAddress(DLL_Handle,'ChangeWindowMessageFilter');
  35. // if Assigned(_ChangeWindowMessageFilter) then
  36. // begin
  37. // _ChangeWindowMessageFilter(WM_COPYDATA, 1);
  38. // _ChangeWindowMessageFilter(WM_COPYGLOBALDATA, 1);
  39. // _ChangeWindowMessageFilter(WM_DROPFILES, 1);
  40. // end;
  41. // finally
  42. // FreeLibrary(DLL_Handle);
  43. // end;
  44. // end;
  45. // except
  46. // end;
  47. //
  48. //end;
  49. class procedure TRealICQUtility.ClearStringList(AStringList: TStringList);
  50. var
  51. AObj: TObject;
  52. begin
  53. if AStringList = nil then
  54. Exit;
  55. while AStringList.Count > 0 do
  56. begin
  57. Aobj := AStringList.Objects[0];
  58. AStringList.Delete(0);
  59. FreeAndNil(AObj);
  60. end;
  61. end;
  62. class procedure TRealICQUtility.FreeStringList(AStringList: TStringList);
  63. var
  64. AObj: TObject;
  65. begin
  66. if AStringList = nil then
  67. Exit;
  68. while AStringList.Count > 0 do
  69. begin
  70. Aobj := AStringList.Objects[0];
  71. AStringList.Delete(0);
  72. FreeAndNil(AObj);
  73. end;
  74. FreeAndNil(AStringList);
  75. end;
  76. class procedure TRealICQUtility.FreeList(AList: TList);
  77. var
  78. AObj: TObject;
  79. begin
  80. if AList = nil then
  81. Exit;
  82. while AList.Count > 0 do
  83. begin
  84. Aobj := AList[0];
  85. AList.Delete(0);
  86. FreeAndNil(AObj);
  87. end;
  88. FreeAndNil(AList);
  89. end;
  90. class function TRealICQUtility.GetServerID(ALoginName: string): string;
  91. var
  92. iStart, iEnd, Len: Integer;
  93. begin
  94. Result := '';
  95. iEnd := AnsiPos('-', ALoginName);
  96. if iEnd < 0 then
  97. Exit;
  98. iStart := AnsiPos('+', ALoginName);
  99. if iStart < 0 then
  100. iStart := 0;
  101. if iEnd <= iStart + 1 then
  102. Exit;
  103. Result := Copy(ALoginName, iStart + 1, iEnd - iStart - 1);
  104. end;
  105. class function TRealICQUtility.SplitString(const Source, Ch: string): TStringList;
  106. var
  107. Temp: string;
  108. iLoop: Integer;
  109. begin
  110. Result := TStringList.Create;
  111. Temp := Source;
  112. iLoop := Pos(Ch, Source);
  113. while iLoop <> 0 do
  114. begin
  115. Result.Add(copy(temp, 0, iLoop - 1));
  116. Delete(temp, 1, iLoop + Length(Ch) - 1);
  117. iLoop := Pos(Ch, Temp);
  118. end;
  119. Result.Add(temp);
  120. end;
  121. class function TRealICQUtility.GetAndClearServerID(var ALoginName: string): string;
  122. var
  123. iStart, iEnd, Len: Integer;
  124. begin
  125. Result := '';
  126. iEnd := AnsiPos('-', ALoginName);
  127. if iEnd < 0 then
  128. Exit;
  129. iStart := AnsiPos('+', ALoginName);
  130. if iStart < 0 then
  131. iStart := 0;
  132. if iEnd <= iStart + 1 then
  133. Exit;
  134. Result := Copy(ALoginName, iStart + 1, iEnd - iStart - 1);
  135. ALoginName := Copy(ALoginName, iEnd + 1, Length(ALoginName) - iEnd);
  136. end;
  137. class function TRealICQUtility.GetGuid: string;
  138. var
  139. Guid: TGUID;
  140. begin
  141. CreateGUID(Guid);
  142. Result := GUIDToString(Guid);
  143. end;
  144. class function TRealICQUtility.ClearCenterServerID(ALoginName: string): string;
  145. var
  146. iStart: Integer;
  147. begin
  148. Result := ALoginName;
  149. iStart := AnsiPos('+', ALoginName);
  150. if iStart < 0 then
  151. Exit;
  152. Result := Copy(ALoginName, iStart + 1, Length(ALoginName) - iStart);
  153. end;
  154. class function TRealICQUtility.ClearServerID(ALoginName: string): string;
  155. var
  156. iStart: Integer;
  157. begin
  158. Result := ALoginName;
  159. iStart := AnsiPos('-', ALoginName);
  160. if iStart < 0 then
  161. Exit;
  162. Result := Copy(ALoginName, iStart + 1, Length(ALoginName) - iStart);
  163. end;
  164. class function TRealICQUtility.GetLocalUID(ACenterServerID, AServerID, ALoginName: string): string;
  165. begin
  166. Result := FullLoginName(ACenterServerID, AServerID, ALoginName);
  167. end;
  168. class function TRealICQUtility.FullLoginName(ACenterServerID, AServerID, ALoginName: string): string;
  169. var
  170. iStart, iEnd, Len: Integer;
  171. begin
  172. Result := ALoginName;
  173. if AServerID = '' then
  174. Exit;
  175. if AnsiPos('-', Result) <= 0 then
  176. begin
  177. if AnsiPos('+', Result) <= 0 then
  178. Result := AServerID + '-' + Result
  179. else
  180. Insert(AServerID + '-', Result, AnsiPos('+', Result) + 1);
  181. end;
  182. if ACenterServerID = '' then
  183. Exit;
  184. if AnsiPos('+', Result) <= 0 then
  185. Result := ACenterServerID + '+' + Result;
  186. end;
  187. end.