1 (edited by wenchester21 2021-06-01 02:30:16)

Topic: About Arrays???? Please Help

Hello my people.
I need help in some things ...

1- How do you declare variables of the arrays type, in its different variants (strings, whole, real etc.)?

2- How to assign the data from different routes (SQLQuery, File TXT, Excel, Grid etc.) to those variables?

3- How to travel each of the elements of the array? Ex: array [A, B, C], show a message with each element of the array, or insert it into a new line of a memo object.

4- Starting from an eg SQLQuery. 'Select Fullname, DNI, Address from person' that sheds say 5 results. How to travel each of those records to perform operations (compare, modify etc.) about them?

PS: Doing this on a SQL function is simple for me, but I want to learn how to handle those things in an MVD script.

Re: About Arrays???? Please Help

1. Array1: array [0..30] of integer;
    Array2: array [0..31, 0...31] of integer;
    Array3: array [0..20] of  string;
   
2. Array1[1]:= var  ;
      
    for i:=0 lten.Count-1 do
       Array1[i]:=lten[i];
  
3. showmessage(Array3[1]);

4. I don't understand the question, maybe this is
   
 var_name := SQLExecute('SELECT  field_name FROM table_name  WHERE id=1');
  OR 
 var_name := SQLExecute('SELECT  "'+var_name+'" FROM table_name  WHERE id=1'+var_name); // IntToStr(var_name)

 SQLExecute('INSERT INTO table_name(field1,field2)VALUES("values1","'+var_name+'")');

 SQLExecute('UPDATE table_name SET field_name="values" ');

Re: About Arrays???? Please Help

Hello

The situation is the following I have two tables, one (main) I use to store the data of people and the other to store data of people imported from an Excel, validate it, modify it if necessary and then pass it to the main table.

All this process of going from one table to another I plan to do it automatically (click on a button).

Some of the validations would be that the DNI is not duplicated, and that if it is already in the main table to discard that record.

Another validation may be that some denominations (country, state, blood, etc.) are in the nomenclator.

In case the validations are not passed, give a message, or mark with a color in the grid the names not found in the nomenclator.

I know this is all handled by records, but ... any idea how to do something like that using scripts?  It is that I have not deepened in the management of records.

Re: About Arrays???? Please Help

Hello, how to declare a record?

5 (edited by wenchester21 2021-06-04 20:31:08)

Re: About Arrays???? Please Help

procedure frm_importdata_Button_ValidateData_OnClick (Sender: TObject; var Cancel: boolean);
var
i,l: integer;
province: Array[0..l] of String;
begin
    frm_importdata.Button_SelectFile.Enabled := False;
    frm_importdata.Button_UploadData.Enabled := False;
    frm_importdata.Edit_FilePath.Enabled := False;
    frm_importdata.TableGrid_DataUploaded.Enabled := False;
    frm_importdata.Button_Delete.Enabled := False;
    frm_importdata.Button_ValidateData.Enabled := False;

    frm_importdata.Label_Task.Caption := '.::VALIDATING DATA TO IMPORT::.';

    If VarToStr(SQLExecute('Select count(imp.province) From import_data imp Where imp.province not in (Select denomination from province)')) <> '0' Then
    Begin
    MessageDlg('There are names of provinces that are not in the Database.', mtError, mbOk, 0);
    frm_importdata.Memo_Logs.Lines.Add('- Provinces: ERROR, There are names of provinces that are not in the Database.');

    l := StrToInt(VarToStr(SQLExecute('Select count(imp.province) From import_data imp Where imp.province not in (Select denomination from province)')));
    province := [VarToStr(SQLExecute('Select imp.province From import_data imp Where imp.province not in (Select denomination from province)'))];

    For i := 0 to (length(province)-1) do
    Begin
    frm_importdata.Memo_Logs.Lines.Add('Error: ' + province[i]);
    End;

    End Else frm_importdata.Memo_Logs.Lines.Add('- Provinces: OK ');

    frm_importdata.Button_SelectFile.Enabled := True;
    frm_importdata.Button_UploadData.Enabled := True;
    frm_importdata.Edit_FilePath.Enabled := True;
    frm_importdata.TableGrid_DataUploaded.Enabled := True;
    frm_importdata.Button_Delete.Enabled := True;
    frm_importdata.Button_ValidateData.Enabled := True;

end;

Supposedly in this part I define the values of the array. That query returns 2 results.

province := [VarToStr(SQLExecute('Select imp.province From import_data imp Where imp.province not in (Select denomination from province)'))];

But when I try to print the values it only prints one instead of two.

 For i := 0 to (length(province)-1) do
    Begin
    frm_importdata.Memo_Logs.Lines.Add('Error: ' + province[i]);
    End;

How could I solve this. I've been researching and could work with records, that's why I asked above, but I have problems declaring a record, I don't know where it goes in the structure, or how it is declared. I tried some ways that I found on the internet but it gives me syntax error.

Internet example:

procedure TForm1.Button1Click(Sender: TObject);
type
  registroPrueba = record
    campo1 : integer;
    campo2 : string;
    campo3 : double;
    campo4 : TStringList;
  end;

var
  registro : registroPrueba;
  listaEjemplo : TStringList;
begin
  registro.campo1 := 43;
  registro.campo2 := 'This is a record test';
  registro.campo3 := 112234;
  //we initialize any TStringList and insert values to it
  listaEjemplo := TStringList.Create;
  listaEjemplo.Add('This is a test');
  listaEjemplo.Add('inserting a list');
  listaEjemplo.Add('in a type "record"');

  //we initialize the TStringList of the registry
  registro.campo4 := TStringList.Create;
  //we insert the previously created list in the registry
  registro.campo4 := listaEjemplo;

  //we show some value from the registry
  showmessage (registro.campo4.Strings[1]);
  showmessage (IntToStr(registro.campo1));
end;
Post's attachments

Attachment icon problem.jpg 93.21 kb, 13 downloads since 2021-06-04