小编pKa*_*ian的帖子

Delphi字符串和引用计数

Delphi使用带字符串的引用计数.

这是否意味着'1234567890'只有一个内存分配,所有a,b,c,d,e和fs都参考它?

 type  
   TFoo = class
    s: string;
   end;

  const 
    a = '1234567890';
    b = a;
    c : string = a;

  var
    d: string;
    e: string;
    f: TFoo;

  function GetStr1(const s: string): string;
  begin
   Result := s;
  end;

  function GetStr2(s: string): string;
  begin
   Result := s;
  end;

  begin
   d := GetStr1(b);
   e := GetStr2(c);
   f := TFoo.Create;
   f.s := a;
  end;
Run Code Online (Sandbox Code Playgroud)

delphi string memory-management reference

6
推荐指数
3
解决办法
2569
查看次数

Delphi 2010中Indy IdHttp Post的问题

我有Indy IdHttp Post方法的问题.使用Delphi 2007编译的函数CallRpc()工作正常,但使用Delphi 2010编译的相同代码引发了异常.

当我将Delphi 2007 Indy TIdHttp更改为Delphi 2010 Indy TIdHttp时,我需要考虑什么?

function CallRpc(const sURL, sXML: string): string;
var
  SendStream : TStream;
  IdHttp     : TIdHttp;
begin
  SendStream := TMemoryStream.Create;
  IdHttp := TIdHttp.Create(nil);
  try
      IdHttp.Request.Accept        := '*/*';
      IdHttp.Request.ContentType   := 'text/sXML';
      IdHttp.Request.Connection    := 'Keep-Alive';
      IdHttp.Request.ContentLength := Length(sXML);

      StringToStream(sXML, SendStream);  
      SendStream.Position := 0;

      Result := IdHttp.Post(sURL, SendStream);
  finally
    IdHttp.Free;
    SendStream.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

增加25.1.2009:

例外是:EIdConnClosedGracefully

回应是这样的:

<?xml version='1.0' encoding='us-ascii'?>
<!DOCTYPE Error [ <!ELEMENT Error (ErrorMessage,DebuggingInfo*)> <!ATTLIST Error Date CDATA #REQUIRED Time CDATA #REQUIRED> <!ELEMENT …
Run Code Online (Sandbox Code Playgroud)

delphi unicode http indy delphi-2010

5
推荐指数
1
解决办法
7685
查看次数

Delphi并防止事件处理

当事件处理已经运行时,如何防止新的事件处理启动?

我按下按钮1和事件处理程序启动例如慢速打印作业.表单按钮,编辑,组合中有几个控件,我希望只有在运行处理程序完成后才允许新事件.

我已经使用fRunning变量来锁定共享事件处理程序中的处理程序.有更聪明的方法来处理这个问题吗?

procedure TFormFoo.Button_Click(Sender: TObject);    
begin
  if not fRunning then
  try
    fRunning := true;
    if (Sender = Button1) then // Call something slow ...
    if (Sender = Button2) then // Call something ...
    if (Sender = Button3) then // Call something ...
  finally
    fRunning := false;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

delphi controls event-handling

5
推荐指数
1
解决办法
6378
查看次数

Delphi并在一个单元中完成

我有两个单位unitA和unitB.类TFoo在unitB中声明.

在单元A的最终确定中调用B.Free是否总是安全的?

它如何依赖于unitA和unitB在dpr中的顺序?

执行unitA终结时,我能确定unitB是否存在?

unit unitB;
interface
type
 TFoo = class
   // code...
  end;
 // code....
end;

unit unitA;
// code..
implementation
uses
 unitB;
var
 A: TStringList;
 B: UnitB.TFoo;

initialization
 A:= TStringList.Create;
 B:= UnitB.TFoo.Create;
finalization
 A.Free;
 B.Free;  // Is it safe to call?
end.
Run Code Online (Sandbox Code Playgroud)

delphi finalization

4
推荐指数
2
解决办法
1万
查看次数

Delphi中程序的静态变量

变量a和b的内存管理有什么区别?

它们是相似的静态变量,但是b的可见性是本地的吗?

在程序或函数中声明静态变量是否可以?

const 
  a: string = 'aaa';

procedure SubMethod;
const 
  b: string = 'bbb';
begin
  a := a + 'a';
  b := b + 'b';
end;
Run Code Online (Sandbox Code Playgroud)

delphi variables static memory-management const

1
推荐指数
1
解决办法
2958
查看次数