如何将TParams类型转为Variant?

本文介绍在Delphi中如何将TParams类型的数据转换为Variant类型,以便于调用需要Variant参数的函数。提供了使用PackageParams和UnpackParams函数的方法。

如何将TParams类型转为Variant?
InParam :TParams;
提供的函数为
function ExecProc(const ProcName: AnsiString; const InParam: Variant): Integer;

如果直接调用
ExecProc('SP_Name', InParam)
编译通不过
如何将InParam转为Variant?

在线等!



------解决思路----------------------
delphi中Variant也是一种数据类型 Tparams 继承自tcollection 是个集合类 继承自tojbect 他们之间的转换 是没办法的。

除非你按照execproc 中variants参数类型解析InParam 组合成所需信息 
------解决思路----------------------
PackageParams应该可以,试试,看它的函数是否会出错。 
------解决思路----------------------
找源码啊,DBClient单元PackageParams声明下面就是UnpackParams
function PackageParams(Params: TParams; Types: TParamTypes = AllParamTypes): OleVariant;
procedure UnpackParams(const Source: OleVariant; Dest: TParams);

 

http://www.myexception.cn/delphi/264838.html

import { ref, watch, isRef } from 'vue'; import { Service, UseRequestOptions, UseRequestResult } from '@/types/use-request'; /** * useRequest 实现 */ export function useRequest<TData = any, TParams extends any[] = any[]>( service: Service<TData, TParams>, options: UseRequestOptions<TData, TParams> = {}, ): UseRequestResult<TData, TParams> { const { manual = false, refreshDeps = [], defaultParams, onSuccess, onError } = options; const data = ref<TData>(); const error = ref<any>(null); const loading = ref<boolean>(false); const lastParams = ref<TParams | undefined>(defaultParams); // 竞态锁,只有一次请求生效 let requestId = 0; async function baseRequest(params?: TParams): Promise<TData | undefined> { loading.value = true; error.value = null; const currentId = ++requestId; const runParams: TParams = // eslint-disable-next-line no-nested-ternary params !== undefined ? params : lastParams.value !== undefined ? lastParams.value : ([] as unknown as TParams); try { const res = await service(...runParams); // 只处理最后一次请求 if (requestId === currentId) { data.value = res; lastParams.value = runParams; onSuccess?.(res, runParams); } return res; } catch (err: any) { if (requestId === currentId) { error.value = err; onError?.(err, runParams); } return undefined; } finally { if (requestId === currentId) { loading.value = false; } } } /** * run 主动执行 */ const run = async (...args: TParams): Promise<TData | undefined> => baseRequest(args as TParams); /** * refresh 依赖参数重新执行 */ const refresh = async (): Promise<TData | undefined> => baseRequest(); // 自动执行 if (!manual) { if (refreshDeps.length > 0) { watch( refreshDeps.map(dep => (isRef(dep) ? dep : dep)), () => { baseRequest(defaultParams); }, { immediate: true }, ); } else { // 自动请求一次 baseRequest(defaultParams); } } return { data, error, loading, run, refresh, }; } 我的这个useRequest hook写的有没有什么问题?帮忙看看,有的话帮忙优化下
08-12
module drawrings_module { #include "ldata.h" #include <stdio.h> #include <math.h> #define RING_GAP {0.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0} #define W_RING 10.0 #define WCELLS 1000 #define HCELLS 1000 void draw_a_ring(LCell Cell_Now,LLayer Layer_Now,LPoint pt1,LPoint pt2,float R_corner,float W_ring) { float Wcells,Hcells; //float R_corner; //float W_ring; float X_base,Y_base; float x0,y0,x1,y1; x0 = pt1.x; y0 = pt1.y; x1 = pt2.x; y1 = pt2.y; Wcells = abs(x1-x0); Hcells = abs(y1-y0); X_base = (x1+x0)/2.0; Y_base = (y1+y0)/2.0; //up border LBox_New (Cell_Now, Layer_Now, X_base-(Wcells-2*R_corner)/2.0, Y_base+Hcells/2.0, X_base+(Wcells-2*R_corner)/2.0, Y_base+Hcells/2.0+W_ring); //left border LBox_New (Cell_Now, Layer_Now, X_base-Wcells/2.0, Y_base-(Hcells-2*R_corner)/2.0, X_base-Wcells/2.0-W_ring, Y_base+(Hcells-2*R_corner)/2.0); //right border LBox_New (Cell_Now, Layer_Now, X_base+Wcells/2.0, Y_base-(Hcells-2*R_corner)/2.0, X_base+Wcells/2.0+W_ring, Y_base+(Hcells-2*R_corner)/2.0); //bot border LBox_New (Cell_Now, Layer_Now, X_base-(Wcells-2*R_corner)/2.0, Y_base-Hcells/2.0, X_base+(Wcells-2*R_corner)/2.0, Y_base-Hcells/2.0-W_ring); //定义圆环 LTorusParams tParams; // left bottom tParams.ptCenter = LPoint_Set(X_base-(Wcells-2*R_corner)/2.0,Y_base-(Hcells-2*R_corner)/2.0); tParams.nInnerRadius = R_corner; tParams.nOuterRadius = R_corner + W_ring; tParams.dStartAngle = 180; tParams.dStopAngle = 270; LTorus_CreateNew(Cell_Now, Layer_Now, &tParams); // left up tParams.ptCenter = LPoint_Set(X_base-(Wcells-2*R_corner)/2.0,Y_base+(Hcells-2*R_corner)/2.0); tParams.dStartAngle = 90; tParams.dStopAngle = 180; LTorus_CreateNew(Cell_Now, Layer_Now, &tParams); // right up tParams.ptCenter = LPoint_Set(X_base+(Wcells-2*R_corner)/2.0,Y_base+(Hcells-2*R_corner)/2.0); tParams.dStartAngle = 0; tParams.dStopAngle = 90; LTorus_CreateNew(Cell_Now, Layer_Now, &tParams); // right bottom tParams.ptCenter = LPoint_Set(X_base+(Wcells-2*R_corner)/2.0,Y_base-(Hcells-2*R_corner)/2.0); tParams.dStartAngle = 270; tParams.dStopAngle = 0; LTorus_CreateNew(Cell_Now, Layer_Now, &tParams); } void drawrings() { LCell Cell_Now = LCell_GetVisible (); LFile File_Now = LCell_GetFile( Cell_Now ); LGrid Grid_Now; LLayer Layer_Now = LLayer_GetCurrent(File_Now); if(LCell_GetLock(Cell_Now)!=0) { LDialog_AlertBox("Error:The Cell is Locked! Unlock it First"); return; } LFile_GetGrid(File_Now, &Grid_Now); long locator_scale = Grid_Now.locator_scaling; float R_corner,W_ring; LPoint pt1,pt2; float x0,y0,x1,y1; R_corner = 100*locator_scale; x0 = 0; x1 = 1000*locator_scale; y0 = 0; y1 = 1000*locator_scale; //W_ring = 13*locator_scale; float Wcells,Hcells; Wcells = 1000*locator_scale; Hcells = 1000*locator_scale; float w,h,r; float gap_list[] = RING_GAP; w = Wcells; h = Hcells; r = R_corner; int k; float gap; for (k=0;k<sizeof(gap_list)/sizeof(gap_list[0]);k++) { gap = gap_list[k]*locator_scale; W_ring = (13.0-gap)*locator_scale; w = w + 2*gap; h = h + 2*gap; r = r + gap; pt1 = LPoint_Set(-w/2.0,-h/2.0); pt2 = LPoint_Set(w/2.0,h/2.0); draw_a_ring(Cell_Now,Layer_Now,pt1,pt2,r,W_ring); r = r + W_ring; w = w + W_ring*2; h = h + W_ring*2; } //运行完成,刷新显示 LDisplay_Refresh(); } void cnt_main ( void ) { LMacro_BindToHotKey ( KEY_F1, "drawrings_gaopeng", "drawrings" ); } } cnt_main();
最新发布
08-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值