Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Store Procedure

Posted on 2004-04-24
8
Medium Priority
?
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

730 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