gpt4 book ai didi

delphi - 重置 PChar 变量

转载 作者:行者123 更新时间:2023-12-03 18:00:02 25 4
gpt4 key购买 nike

对delphi win 32编程了解不多,希望有人能解答我的问题。

我将重复的 l_sGetUniqueIdBuffer 保存到我想避免的数据库中。

l_sGetUniqueIdBuffer 在行之间实际上是不同的(l_sAuthorisationContent 的值是 xml,我可以看到通过调用 getUniqueId 生成的不同值)。这个问题是间歇性的(重复很少......)行之间的更新日期之间只有毫秒差异。

给定:

(删去不必要的代码)

var
l_sGetUniqueIdBuffer: PChar;
FOutputBufferSize : integer;

begin
FOutputBufferSize := 1024;
...
while( not dmAccomClaim.ADOQuClaimIdentification.Eof ) do
begin

// Get a unique id for the request
l_sGetUniqueIdBuffer := AllocMem (FOutputBufferSize);

l_returnCode := getUniqueId (m_APISessionId^, l_sGetUniqueIdBuffer, FOutputBufferSize);

dmAccomClaim.ADOQuAddContent.Active := False;
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pContent').Value := (WideString(l_sAuthorisationContent));
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pClaimId').Value := dmAccomClaim.ADOQuClaimIdentification.FieldByName('SB_CLAIM_ID').AsString;
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pUniqueId').Value := string(l_sGetUniqueIdBuffer);
dmAccomClaim.ADOQuAddContent.ExecSQL;

FreeMem( l_sAuthorisationContent, l_iAuthoriseContentSize );

FreeMem( l_sGetUniqueIdBuffer, FOutputBufferSize );
end;
end;

我想我需要知道,l_sGetUniqueIdBuffer 中的值是否正在为每一行重置?

最佳答案

AllocMem实现如下

function AllocMem(Size: Cardinal): Pointer;
begin
GetMem(Result, Size);
FillChar(Result^, Size, 0);
end;

是的,l_sGetUniqueBuffer 指向的值将始终重置为空字符串。

调试

var
l_sGetUniqueIdBuffer: PChar;
FOutputBufferSize : integer;
list: TStringList;
begin
FOutputBufferSize := 1024;
...

list := TStringList.Create;
try
list.Sorted := True;
while( not dmAccomClaim.ADOQuClaimIdentification.Eof ) do
begin

// Get a unique id for the request
l_sGetUniqueIdBuffer := AllocMem (FOutputBufferSize);

l_returnCode := getUniqueId (m_APISessionId^, l_sGetUniqueIdBuffer, FOutputBufferSize);

dmAccomClaim.ADOQuAddContent.Active := False;
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pContent').Value := (WideString(l_sAuthorisationContent));
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pClaimId').Value := dmAccomClaim.ADOQuClaimIdentification.FieldByName('SB_CLAIM_ID').AsString;
dmAccomClaim.ADOQuAddContent.Parameters.ParamByName('pUniqueId').Value := string(l_sGetUniqueIdBuffer);

if list.IndexOf(l_sGetUniqueIdBuffer) <> - 1 then
write; //***** Place a breakpoint here.
list.Add(l_sGetUniqueIdBuffer);

dmAccomClaim.ADOQuAddContent.ExecSQL;

FreeMem( l_sAuthorisationContent, l_iAuthoriseContentSize );

FreeMem( l_sGetUniqueIdBuffer, FOutputBufferSize );
end;
finally
list.Free;
end;
end;

关于delphi - 重置 PChar 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2489891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com