小编Lio*_*ain的帖子

Delphi中的Generic holding Records中的等于运算符

我有一个泛型列表,我想在其中放入一些记录或一些类

TMyList<T> = class
private
  fCount: Cardinal;
  fItems: array of T;
public
  constructor Create(aSize: Integer);
  procedure UpdateItem(const x: T);
end;
Run Code Online (Sandbox Code Playgroud)

但我不能编译

procedure TMyList<T>.UpdateItem(const x: T);
var
  I: integer;
begin
  for I := 0 to fCount - 1 do
    if fItems[I] = x then begin  // <- error  E2015
    //do update
    break;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

它适用于具有此声明的类:TMyList<T : class> = class但是它不再能够保存记录.

当然,为了记录我声明class operator Equal(Left, Right : TMyRecord) : Boolean;,这MyRecord1 = MyRecord2将编译.

delphi record delphi-xe

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

Delphi中Dijkstra最短路径搜索的优化

我正在寻找建议来加速我在加权图上实现Dijkstra最短路径搜索,该加权图是方形矩阵N x N.水平顶点上的权重称为H(相对于垂直方向的权重).

一张图片胜过千言万语:

一张图片胜过千言万语!http://lionelgermain.free.fr/img/graphe.png

当然,这是更大的应用程序的一部分,但我在这里提取了相关的位:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
 N = 200; //Working on a grid of N x N, here for a quick test, in practice, it's more 10000

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  end;

  TNode = class
  public
    ID, //Number of the Node
    origin, //From which Node did I came?
    weight : integer; //The total weight of the path …
Run Code Online (Sandbox Code Playgroud)

delphi list dijkstra

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

使用delphiXE中的pchar参数调用delphi 2006 dll

自从我从delphi 5升级到XE后,我很难使用前一段时间编译的特定Dll.我的阻塞点似乎与unicode/ansi字符有关,但我还没有找到如何解决问题

这是一个程序示例:

procedure GetFilename(Buffer: PChar; BufSize: Integer); stdcall;
Run Code Online (Sandbox Code Playgroud)

在我的代码中,我这样称呼它

implementation    
procedure GetFilename; external 'myDll.dll' name 'GetFilename';
procedure myproc
var
  buffer : Array [0..255] of Char;
begin
  GetFilename(buffer, length(buffer)-1);
  Showmessage(buffer); //This gives me chinese character
end; 
Run Code Online (Sandbox Code Playgroud)

缓冲区包含:

byte((@buffer[0])^); // 67 which is the ASCII for C
byte((@buffer[1])^); // 92 which is the ASCII for \
Run Code Online (Sandbox Code Playgroud)

我期待正常的是以"C:\"开头的字符串

有人遇到过同样的问题吗?

delphi unicode dll char delphi-xe

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

标签 统计

delphi ×3

delphi-xe ×2

char ×1

dijkstra ×1

dll ×1

list ×1

record ×1

unicode ×1