function OrdersAutoId(cdst: TClientDataSet; table_name, keyfield, prefix: string): pchar;stdcall;
var
id: string;
linkstr: string;
count: integer;
sql: string;
begin
//getMem(rs, 256); //get memory
id := pchar(formatdatetime('yyyyMMdd', date())); sql := pchar('select count(*) from '+ table_name +' where '+ keyfield +' like ''%'+ id +'%'';');
try
ExecuteQuery(cdst, sql); if cdst.Fields[0].AsInteger = 0 then
id := id + pchar('0001')
else
begin
count := cdst.Fields[0].AsInteger;
if length(inttostr(count + 1)) = 1 then
id := id + '000' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 2 then
id := id + '00' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 3 then
id := id + '0' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 4 then
id := id + inttostr(count + 1);
end; linkstr := prefix + id;
Result := linkstr; //but does not free entil
except
on e: exception do
begin
showmessage(e.Message);
Result := strcat(prefix, pchar(formatdatetime('yyyymmdd', date())));
end;
end;
end;上面那个函数,如果参数跟返回值都用pchar的话,值传不到主程序中;如果都用string的话,就invalid pointer operation错误;中间过程的变量取值全部都是正确的,就是到最后result时出错,超级寒那
var
id: string;
linkstr: string;
count: integer;
sql: string;
begin
//getMem(rs, 256); //get memory
id := pchar(formatdatetime('yyyyMMdd', date())); sql := pchar('select count(*) from '+ table_name +' where '+ keyfield +' like ''%'+ id +'%'';');
try
ExecuteQuery(cdst, sql); if cdst.Fields[0].AsInteger = 0 then
id := id + pchar('0001')
else
begin
count := cdst.Fields[0].AsInteger;
if length(inttostr(count + 1)) = 1 then
id := id + '000' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 2 then
id := id + '00' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 3 then
id := id + '0' + inttostr(count + 1)
else if length(inttostr(count + 1)) = 4 then
id := id + inttostr(count + 1);
end; linkstr := prefix + id;
Result := linkstr; //but does not free entil
except
on e: exception do
begin
showmessage(e.Message);
Result := strcat(prefix, pchar(formatdatetime('yyyymmdd', date())));
end;
end;
end;上面那个函数,如果参数跟返回值都用pchar的话,值传不到主程序中;如果都用string的话,就invalid pointer operation错误;中间过程的变量取值全部都是正确的,就是到最后result时出错,超级寒那
解决方案 »
- 急急急 为什么我线程不能终止 请高手指点
- 关于DLL的问题,我没有办法了,请各位帮忙啊
- fast report 是否支持中文字段?
- delphi 图表
- DBGrid怎样设置行高?
- 人事管理系统参考!超值100分!!!!
- 如何用Delphi实现把Word文档以二进制的形式存进SQL Server2000数据库中
- listview里的item。。。
- 数组指针取值的问题
- Delphi 程序运行中会弹出“内存不能为读”的对话框,点击确定以后程序还可以运行,为什么?怎么解决?
- 想做一个通用的、对数据集中的数据进行筛选的东东,同仁们能不能给个好思路?
- 要把指定数据库中的所有表名显示在combobox中,用代码怎么实现呢?谢谢各位大侠小侠!
是你的处理出问题吧?http://lysoft.7u7.net
现在数据传入传出都是pchar,内部用string,一切都过去了