Solved

Store Procedure

Posted on 2004-04-24
8
198 Views
Last Modified: 2010-04-05
How can I create a procedure that stores a value to a list of variables.

I tried this:

Procedure StoreInt( value:integer; var arr:array of integer);
var i:integer;
begin
      For i:=1 to high(arr) do
      arr[i]:=value;      
end;


var x,y,z:Integer
........
StoreInt(10,[x,y,z]);


When I compile the application I receive the following error: "Constant object cannot be passed as var parameter"
0
Comment
Question by:ronnix
  • 3
  • 2
8 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10907306
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  type
     DynamicArray = array of integer;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Procedure StoreInt( value : integer; var arr : DynamicArray);
var
  i : integer;
begin
  For i:= 1 to high(arr) do
     arr[i]:=value;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  arr : DynamicArray;
begin
  StoreInt(10,arr);
end;

end.
0
 

Author Comment

by:ronnix
ID: 10908541
I didn't understood me. i want to store a single value to more variables not to the items of an array;

i.e
I replace
x:=10;
y:=10;
z:=10;

with StoreInt(10,x,y,z);

So that, how can i make x,y,z be equal with 10 after calling StoreInt as above?
0
 

Author Comment

by:ronnix
ID: 10912800
You didn't understood me. i want to store a single value to more variables not to the items of an array;

i.e
I replace
x:=10;
y:=10;
z:=10;

with StoreInt(10,x,y,z);

So that, how can i make x,y,z be equal with 10 after calling StoreInt as above?
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 150 total points
ID: 10915912

// after StoreInt you can make a procedure which transform the variant array A into array of Integers

Procedure StoreInt( value : integer; var arr : Variant);
var
  counter    : Integer;
begin
  For counter := VarArrayLowBound(arr, 1) to VarArrayHighBound(arr, 1) do
    begin
      arr[counter] := value;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x, y, z : Integer;
  a : variant;
begin
  a := VarArrayOf([x, y, z]);
  StoreInt(10, a);

  Label1.Caption := VarToStr(a[0]);
  Label2.Caption := VarToStr(a[1]);
  Label3.Caption := VarToStr(a[2]);
end;
0
 

Author Comment

by:ronnix
ID: 10920245
it works but after calling the StoreInt procedure I must convert the values:
i.e
x:=vartoint(a[0]); etc

and is quicker to use the classic method:
x:=10 etc.

Don't you know any other method?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open a URL with Internet Explorer in a new tab (not a new window) 1 121
RESTRequest Parameter 4 43
Wincontrol not (correctly) drawn 15 42
DBCtrlGrid, Delphi, Scroll 8 39
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question