小编Leo*_*Leo的帖子

积累面积的计算

我正在寻找GIS/Geometric算法:

我有1000个点随机分布在一个大区域(如城市),我怎样才能找到所有超过15分的小区域?如下图所示:

在此输入图像描述

每个点都有自己的纬度和经度坐标.小面积小于200米x 200米.

c c++ delphi gis

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

Delphi的简单类型是否安全?

我声明了两个全局变量:

var
  gIsRunning: Boolean = False;
  gLogCounter: Integer = 0;
Run Code Online (Sandbox Code Playgroud)

这些变量仅在主线程中写入,并在其他线程中读取.在这种情况下,这些变量是否安全?

delphi multithreading thread-safety

12
推荐指数
4
解决办法
7696
查看次数

需要支持D2009的xml组件

我正在寻找支持Delphi 2009的xml组件/库.

谢谢!

xml delphi delphi-2009

10
推荐指数
2
解决办法
826
查看次数

为什么使用FreeMem/Dispose例程释放内存,但没有内存减少?

我使用AllocMem/GetMem/New例程来分配内存,然后使用FreeMem/Dispose例程来释放内存.但我发现(通过Process Explorer)进程的内存大小没有减少.

如果我使用GlobalAllocPtr/HeapAlloc和GlobalFreePtr/HeapFree API,内存大小将减少.

这是我的测试代码:

type
  TMyRec = record
    Name: string;
    TickCount: Cardinal;
    Buf: array[0..1024 - 1] of byte;
  end;
  PMyRec = ^TMyRec;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FList.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FList := TList.Create;
  ReportMemoryLeaksOnShutdown := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  Size: Integer;
  Rec: PMyRec;
  Heap: Cardinal;
begin
  Size := SizeOf(TMyRec);
  Heap := GetProcessHeap;
  for I := 0 to 2000 - 1 do
  begin
    Rec := AllocMem(Size);                              // Delphi …
Run Code Online (Sandbox Code Playgroud)

memory delphi

10
推荐指数
2
解决办法
4662
查看次数

Confusion of thread synchronization problem

It makes me confused when I read the article by Zarko Gajic today:

"Multithreaded Delphi Database Queries"

Article URL: http://delphi.about.com/od/kbthread/a/query_threading.htm

Sourecode: http://delphi.about.com/library/weekly/code/adothreading.zip

With the code of "TCalcThread.Execute" procedure, Why the following code do not need to be placed in the Synchronize() method to run?

Line 173:    ListBox.Clear;  
Line 179:    ListBox.Items.Insert(......);
Line 188:    ListBox.Items.Add('*---------*');
Line 195:    TicksLabel.Caption := 'Ticks: ' + IntToStr(ticks);
Run Code Online (Sandbox Code Playgroud)

These codes are operating the VCL components, and are related to the UI updates. In my knowledge, …

delphi multithreading synchronize

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

如何抓住Fn +?笔记本上有钥匙?

我可以用我的程序捕获Fn + F3(或Fn + F2 ....)键吗?

delphi

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

在HostApp和DLL之间预分配内存

我有一个提供解码功能的DLL,如下所示:

function MyDecode (Source: PChar; SourceLen: Integer; var Dest: PChar; DestLen: Integer): Boolean; stdcall; 
Run Code Online (Sandbox Code Playgroud)

HostApp调用"MyDecode",并转移到Source,SourceLen和Dest参数,DLL返回解码的Dest和DestLen.问题是:HostApp无法知道解码的Dest长度,因此不知道如何预先分配Dest的内存.

我知道可以将"MyDecode"分成两个函数:

function GetDecodeLen (Source: PChar; SourceLen: Integer): Integer; stdcall;  // Return the Dest's length
function MyDecodeLen (Source: PChar; SourceLen: Integer; var Dest: PChar): Boolean; stdcall; 
Run Code Online (Sandbox Code Playgroud)

但是,我的解码过程非常复杂,因此如果分成两个功能会影响效率.

有更好的解决方案吗?


是亚历山大,这可能是一个很好的解决方案.HostApp代码:

//... 
MyDecode(....) 
try 
  // Use or copy Dest data 
finally 
  FreeDecodeResult(...) 
end;
Run Code Online (Sandbox Code Playgroud)

DLL代码:

function MyDecode(...): Boolean;
begin
  // time-consuming calculate

  // Allocate memory
  GetMem(Dest, Size);   
  // or New()?
  // or HeapAlloc()?
end;

procedure FreeDecodeResult(Dest: PChar);
begin
  FreeMem(Dest); …
Run Code Online (Sandbox Code Playgroud)

memory delphi dll

6
推荐指数
2
解决办法
1253
查看次数

Trunc()函数

看下面的代码,为什么Trunc函数的结果不同?

procedure TForm1.Button1Click(Sender: TObject);
var
  D: Double;
  E: Extended;
  I: Int64;
begin
  D := Frac(101 / 100) * 100;
  E := Frac(101 / 100) * 100;
  I := Trunc(D);
  ShowMessage('Trunc(Double): ' + IntToStr(I));  // Trunc(Double): 1
  I := Trunc(E);
  ShowMessage('Trunc(Extended): ' + IntToStr(I)); // Trunc(Extended): 0
end;
Run Code Online (Sandbox Code Playgroud)

delphi floating-point

5
推荐指数
2
解决办法
4691
查看次数

寻找二进制编码的序列化机制

准备开发内部通信协议,尝试使用XML或者JSON作为序列化机制,但是文本方式效率较低,导致数据包量大。所以,我希望使用二进制序列化编码机制。但是,我找了半天,没找到跨语言、Delphi支持的机制。

delphi binary serialization protocols

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

PostgreSQL 的大数组 DML (FireDAC) 工作失败

我需要将大量行插入到我的 PostgreSQL(v9.5) 表中。

这是表格:

create table TaskLog(
  id serial,
  taskid integer,
  x double precision,
  y double precision,
  loc character varying(50),
  speed smallint,
  gpstime timestamp without time zone,
  veh character varying(16),
  vin character(17),
  regdate date,
  enabled boolean,
  remake character varying(100),
  isdel boolean,
  alarm integer,
  CONSTRAINT pk_delphi_id PRIMARY KEY (id)
 )
Run Code Online (Sandbox Code Playgroud)

我使用 FireDAC(Delphi XE10.1) 插入行:

function RandomStr(aLength : Integer) : string;
var
  X: Integer;
begin
  if aLength <= 0 then exit;
  SetLength(Result, aLength);
  for X:=1 to aLength do
    Result[X] := Chr(Random(26) + …
Run Code Online (Sandbox Code Playgroud)

delphi postgresql firedac

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