English 中文(简体)
书写TumoryStream——监视点
原标题:Writing string to TMemoryStream - Pointer to string
  • 时间:2010-09-27 21:37:42
  •  标签:
  • delphi
最佳回答

1 <代码>SourceString***版本更易读。 我宁愿在点人完全需要时不要与他们合作。

2 本法典将与统法协会合作not。 页: 1 (这将与Delphi的大学前和后版本同时进行。) 但是,除非你重新大力使用非安西的果园,否则这将成为大量浪费空间。 我想做的是:

procedure TStreamEx.WriteString(const data: string);
var
  len: cardinal;
  oString: UTF8String;
begin
  oString := UTF8String(data);
  len := length(oString);
  self.WriteBuffer(len, 4);
  if len > 0 then
    self.WriteBuffer(oString[1], len);
end;

procedure TStreamEx.ReadString(const data: string);
var
  len: cardinal;
  iString: UTF8String;
begin
  self.ReadBuffer(len, 4);
  if len > 0 then
  begin
    SetLength(iString, len);
    self.ReadBuffer(iString[1], len);
    result := string(iString);
  end
  else result :=   ;
end;

(这是<代码>级辅助器,用于TStream。) 我写道,阅读和书写从流到和流出的各种东西非常容易。 但是,如果你不喜欢班级助手,那么把基本想法改为另一种形式就太困难了。

问题回答

在生成的网上编码中:

  • pointer(aString)^ will pass the string address directly to the procedure/function/method;
  • aString[1] will call UniqueString then pass the string address to the procedure/function/method.

因此,如果你重新读取数据,则将使用<>点(aString)。

如果你要修改所谓的功能,将使用<>String >。

实际上,我使用的是pointer(aString)^,该标准产生了更有效的编码。

请注意,这一暗含的<>UniqueString并不十分缓慢:如果目前援引该示例为1,(这意味着使用该示意图的法文本中仅有一部分可能),则立即返回。 但是,在<>UniqueString上,有一处LOCK的顶板用于检查参考值,而使用LOCK的树像并不多为友好。 因此,我试图避免在Im编码时使用aString?

附加说明:如果aString,pointer(aString)将返回nil





相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签