Solved

Store Procedure

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 557
Tvertscrollbox like a whatsapp layout delete messages 1 50
Firemonkey Queue list 1 51
Firemonkey Listview item popup menu ? 1 77
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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