whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

51 Visitors Online


 
...make a procedure/function with variable parameter count?
Autor: Andrei A. Lobanov
[ Print tip ]  

Tip Rating (25):  
     


{ .... }

type
  
VA_FN = function(const par1, par2{, ...}: Pointer): Boolean;
                   cdecl varargs;

{ .... }

//
// varargs without "external" keyword
//
function fn(const par1, par2{, ...}: Pointer): Boolean; cdecl;
var
  
last_arg: Pointer absolute par2;
  ptr_args: array[0..MAXLONG shr 2] of Pointer absolute last_arg;
  dw_args: array[0..MAXLONG shr 2] of Cardinal absolute last_arg;
  s_args: array[0..MAXLONG shr 2] of PChar absolute last_arg;
  w_args: array[0..MAXLONG shr 2] of WideString absolute last_arg;
begin
  
// ptr_args[1] is first optional argument
  
Result := (ptr_args[1] {par3} = Pointer(1)) and
    
(dw_args[2] {par4} = 2) and
    
(string(ptr_args[3]) = 'CHAR') and
    
(w_args[4] = 'WCHAR');
end;

procedure test_fn;
begin
  
// VA_FN typecast
  
VA_FN(@fn)({par1}nil{par2}nil{par3}Pointer(1), {par4}2, {par5}'CHAR',
    {par6}WideString('WCHAR'));
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners