English 中文(简体)
如何使用德尔菲的变量阵列
原标题:How to use variant arrays in Delphi

我有两个Delphi7方案:一台COM自动化服务器(EXE)和正在使用自动化服务器的其他方案。

我需要从一个方案向另一个方案通过一系列的 by。

在进行一些搜索后,我发现,使用变量阵列是走路(如果你知道任何更好的方法,请更正)。

My question is: How do I create a variant array in one program, and then how do I read its values in the other?

我知道VarArrayCreate和VarArrayLowBound/VarArrayHighBound的情况,但我不知道如何适当做到这一点。

感谢!

最佳回答

你们就是这样:

宣言

var
  VarArray: Variant;
  Value: Variant;

之后是:

VarArray := VarArrayCreate([0, Length - 1], varVariant);

或者

VarArray := VarArrayCreate([0, Length - 1], varInteger);

取决于数据类型。 接着,你也这样做:

i := VarArrayLowBound(VarArray, 1);
HighBound := VarArrayHighBound(VarArray, 1);

while i <= HighBound do
begin
  Value := VarArray[i];
  ... do something ...
  Inc(i);
end;

最后,当你不需要时,你就会清除阵列。 EDIT: (这是任择性的,见。 在2009年德尔菲,我是否需要自由的变量阵列? iii

VarClear(VarArray);

这就是说的。 另一例见官方网站

EDIT:

阵列只应当建立一次。 然后,就如上所示。

问题回答

另一方:

(假设价值是变数参数,元件类型为广度)

var
  Source: PWideStringArray;

if VarIsArray(Value) then begin
  Source:= VarArrayLock(Value);
  try
    for i:= 0 to TVarData(Value).VArray^.Bounds[0].ElementCount - 1 do
      DoWhatEverYouWantWith(Source^[i]);
    end;
  finally
    VarArrayUnlock(Value);
  end;
end;  




相关问题
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 "...

热门标签