Solved

Store Procedure

Posted on 2004-04-24
8
207 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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