1

(4 replies, posted in Script)

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;

2

(4 replies, posted in Script)

Hello, how to declare a record?

3

(4 replies, posted in Script)

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.

4

(6 replies, posted in General)

derek wrote:

Hi,
To disable adding, editing and deleting treeview items, try it like this (see attached).
Not sure why you would want to do this though.
Derek.

Hi Derek and Jean
And how do I return the tree to normal?

5

(4 replies, posted in Script)

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.

6

(6 replies, posted in General)

hi jean and derek, thanks for your solutions, they gave me the push to what i am doing.  I would only have question 2, if you have any ideas, tell me. Thanks

7

(6 replies, posted in General)

-How can you create a menu for a form other than the main one?
-In the tree view object, how can it be disabled by code that can be created, edited or deleted?
-How could the sort option be disabled in the grid without disabling the grid?

8

(7 replies, posted in Script)

works perfectly, thanks for the idea.

9

(7 replies, posted in Script)

The idea is the following.  I have two DateTimerPickers that I use to select a date range, I want to insert a record for each day within the selected range, ignoring Saturday and Sunday.

I have already resolved to insert a record for each day within the selected range, but I need help to ignore Saturdays and Sundays, that is, the weekend.

Wen

10

(9 replies, posted in General)

Is there the possibility that 2 events are seen on the calendar grid at the same time? They can be identified by different colors.  Xq in the examples when 2 tasks are registered at the same time, one appears on top of the other.

11

(3 replies, posted in General)

I would do it like this.

procedure CalculateTotal;
begin
    frm_main.labBA.caption := StrToInt(frm_main.edH.text) / StrToInt(frm_main.edAB.text); // Calculate
end;

procedure frm_main_edAB_OnChange (Sender: string);
begin
If (frm_main.edAB.text = '') then
begin
    ShowMessage('Division x 0 is not permitted');
end Else
begin
    CalculateTotal;
end;
end;

procedure frm_main_edH_OnChange (Sender: string);
begin
If (frm_main.edAB.text = '') then
begin
    ShowMessage('Division x 0 is not permitted');
end Else
begin
    CalculateTotal;
end;
end;

of course, you know that division by zero is going to give you the same error, you must manage this detail.

12

(7 replies, posted in Script)

ehwagner wrote:

I totally agree with CDB. It seems you are making this more difficult than it really should be. See attached. You can accomplish what you want with very little script. And the only reason for the script is because of the awkward setup of the forms. I did make an assumption and that is there will only be one record in this table. If there is going to be more than one record then your forms will need to change to accommodate such.

I will review and tell you later, thanks for taking a look.

13

(7 replies, posted in Script)

CDB wrote:

Just a quick question, if you are wanting to save the image to the database, why aren't you using the dbImage component?

Using this would make your life much easier.

I have never used this component with scripts, so advanced actions with it become difficult, but it is all a matter of study and looking at some examples. Thanks brother

14

(7 replies, posted in Script)

wenchester21 wrote:

Here I leave you a project with what I want to do.  In the scripts there are commented lines, those comments correspond to things that I have no idea how to proceed.  It may be necessary to change the data type of the variables associated with the images.  If you could figure out how to load and save the images to and from the db in the objects of the 2 forms, it would be very helpful.

HELP, HELP ☝️☝️☝️☝️☝️☝️☝️

15

(7 replies, posted in Script)

Here I leave you a project with what I want to do.  In the scripts there are commented lines, those comments correspond to things that I have no idea how to proceed.  It may be necessary to change the data type of the variables associated with the images.  If you could figure out how to load and save the images to and from the db in the objects of the 2 forms, it would be very helpful.

16

(7 replies, posted in Script)

Hello people.  I am having a data type problem to do an insert into a table.  Below I put the complete procedure to get the idea.

procedure frm_conf_ihs_OnShow (Sender: TObject; Action: string);
var
v_checkconf,v_titulo_left,v_lema_left,v_tiempo_actualizacion_datos_ds: Integer;
v_banner_logo,v_banner_banner,v_banner_titulo,v_banner_lema: String;
begin

v_checkconf := SQLExecute('SELECT count(id) FROM conf_ihs_est');

If (v_checkconf = 0) then
begin
MessageBox('No se ha encontrado una configuración, se establecerá una por defecto.','Configuración Dashboard',MB_Ok+MB_ICONINFORMATION);

v_banner_logo := '';
v_banner_banner := '';
v_banner_titulo := 'InteligenciaVial';
v_banner_lema := 'Escuela de Automovilismo';
v_titulo_left := 120;
v_lema_left := 120;
v_tiempo_actualizacion_datos_ds := 20000;

SQLExecute('INSERT INTO conf_ihs_est'+
          '(banner_logo, banner_banner, banner_titulo, banner_lema, titulo_left, lema_left, tiempo_actualizacion_datos_ds) '+
          'VALUES("'+v_banner_logo+'","'+v_banner_banner+'","'+v_banner_titulo+'","'+v_banner_lema+'",'+v_titulo_left+','+v_lema_left+','+v_tiempo_actualizacion_datos_ds+')');
End;

end;

The error gives me with the integer values.  I think it is the syntax that I am using or if the data has to be cast.

Another question, if you notice I want to insert by default 2 images.  What is the data type for an image?

17

(2 replies, posted in General)

Brother, with my visual database you can do everything, or almost everything, having well defined what you want.  Define a database structure and mount the application on top of it.

18

(8 replies, posted in General)

This software does not provide a tool for that task.  My recommendation is to share the database by network and that from several clients have access to it from your created software.  And to solve your already created problem, I recommend using a data comparator, I use the software from the EMS company.  They generate a script that you can run to migrate the data.  It is always advisable to save and check first that everything is fine.  That is why I recommend the first option.

19

(9 replies, posted in Script)

Regular expression for dates

^(((0[1-9]|1[012])/(0[1-9]|1\d|2[0-8])|(0[13456789]|1[012])/(29|30)|(0[13578]|1[02])/31)/[2-9]\d{3}|02/29/(([2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$

20

(9 replies, posted in Script)

I want to use the regular expression to validate that the date type data is correct.  The expression that I put in the example does not correspond to a date but to a decimal number.  But that's the least of it, by putting the correct regular expression you can already validate the date or whatever you want.  This route is the one that I would see as the most suitable but the one you showed me is also quite good.  It works for me to show the messages, they are to know if it validates correctly, the actions I put them later.

21

(9 replies, posted in Script)

brian.zaballa wrote:

This is not a regex but do the trick. I hope you can get some idea with this one.

Hello brother, the solution you gave me was useful, I only modified the part of the date condition for this.  Thanks a lot.

if yy <= StrToInt(Copy(DateToStr(date),9,2)) then 
yy := (StrToInt(Copy(DateToStr(date),7,2))*100)+yy 
else yy := ((StrToInt(Copy(DateToStr(date),7,2))-1)*100)+yy;

Thanks a lot.

22

(9 replies, posted in Script)

Hello, any idea how to make this work?

procedure frm_add_estudiante_ed_CI_OnChange (Sender: TObject);
var
RegularExpression : TRegEx;
Match : TMatch;

begin
  RegularExpression.Create('[-+]?[0-9]*\.?[0-9]+');
  Match := RegularExpression.Match(ed_CI.Text);
  if Match.Success then
   begin
    ShowMessage('Success.');
   end else
    begin
     ShowMessage('Not successful.');    
    end;
end;

23

(4 replies, posted in SQL queries)

You do not need to implement a script for this, in the properties of the date objects look for filter and define if you look for equal, greater, less etc ...

24

(9 replies, posted in Script)

I explain the situation.  In a text field whose maximum length is 11 a string of type text is inserted.  What is inserted corresponds to the identification number of the person or the number of her passport.  The passport number has 7 digits and it is not necessary to validate it for now, but the identification number of the person if it maintains a pattern, of the 11 digits the first 6 are the date of birth (yymmdd) of that person and the last digit  indicates sex, even for the feminine and odd for the masculine.  What I want to validate is that in the OnChange event of the text box if the number has 11 digits that the first 6 always correspond to a valid date data.

procedure frm_add_estudiante_ed_CI_OnChange (Sender: TObject);
var
v_largo_string:integer;
v_string,v_substring,v_substringdd,v_substringmm,v_substringyy:string;
v_date:TDateTime;
begin
v_largo_string := Length(frm_add_estudiante.ed_CI.Text);

If v_largo_string = 11 Then
begin
v_string := frm_add_estudiante.ed_CI.Text;
v_substringdd := Copy(v_string,5,2);
v_substringmm := Copy(v_string,3,2);
v_substringyy := Copy(v_string,1,2);
v_substring := v_substringdd + '/' + v_substringmm + '/' + v_substringyy;
v_date := StrToDate(v_substring); // The error is here when the data does not have a valid date format.

if FormatDateTime('yyyy',v_date) > FormatDateTime('yyyy',Now) then
begin
v_substring := v_substringdd + '/' + v_substringmm + '/' + v_substringyy;
v_date := IncMonth(StrToDate(v_substring),-1200);
frm_add_estudiante.DateTimePicker_FNacimiento.DateTime := v_date;
End Else
begin
v_substring := v_substringdd + '/' + v_substringmm + '/' + v_substringyy;
v_date := StrToDate(v_substring);
frm_add_estudiante.DateTimePicker_FNacimiento.DateTime := v_date;
end;

End Else
begin
frm_add_estudiante.DateTimePicker_FNacimiento.Checked := False;
end;
end;

25

(3 replies, posted in General)

it depends on the complexity of the database structure.  If the new versions do not bring changes in the structure of the database, you can use the import of the software itself.

if it is the opposite, then you will have to implement the import yourself.  In the forum search type import export and several suggestions will appear.

Wen