301

(5 replies, posted in General)

Jack,
Not sure if this answering your question. But to point to your database on your network you will load your application project on each of your user computers. Then in each user application you will need to enter the network drive where your database is located using the settings menu option. See below.

https://s17.postimg.org/oiomlr30v/Database_Location.jpg


If you plan to do any updating to the network database by users in the future, you will need to do some other work because SQLite does not play well on a network with multiple users updating simultaneously and you can actually corrupt your db.

302

(23 replies, posted in General)

Dimitry,
I don't know if I hit on a bug or not for searchable combobox. Take a look at the attached sample. Click on the combobox and type a 1 into the field to filter the list without clicking on the down arrow of the combobox first. When you do this, the mouse cursor disappears.  If you click on the arrow to dropdown the list first and then start typing in the filter, the mouse cursor stays intact as it should. Can you look into why the mouse cursor disappears? Thank you.

303

(23 replies, posted in General)

Excellent. Thank you Dimitry.

304

(23 replies, posted in General)

Thank you Dimitry. Would it be asking too much to include your examples that you provided in the forum. It would help in understanding the syntax of the new functionality. Appreciate it.

305

(23 replies, posted in General)

Dimitry,
Would you mind posting the new items in versions 4.0, 4.1 and 4.2. I remember seeing what's new in the forum for these versions, but apparently they have been removed. I like to keep track of new functionality in MVD for reference material. I appreciate it. Thank you.

306

(2 replies, posted in General)

Adam,
Here you go. On the selected invoice I checked to see if a row was selected and if not then it selects the first one. You may want to put in a message instead.

307

(3 replies, posted in General)

Adam,
Not exactly sure what you mean by:

form1Show selecting first records on relevant grids as switching tab pages automatically.


If it's what I think you mean, you probably also need to set corresponding tablegrid rows when changing tabsheets ( Pagecontrol OnChange event)

308

(3 replies, posted in General)

Adam,
One thing that I notice is in your MyScrollSUPPLIER procedure you are loading the tgMainProducts selectedrow. I think it should be tgMainSupplier selectedrow.

procedure MyScrollSUPPLIER;
begin
if Form1.PageControl1.ActivePageIndex = 1 then
   begin
   if Form1.tgMainSupplier.selectedrow < 0 then Form1.tgMainSupplier.selectedrow := 0;
      vrowid := Form1.tgMainProducts.selectedrow;          // This should be vrowid := Form1.tgMainSupplier.selectedrow;
      Form1.tgMainSupplier.selectedrow := vrowid;
      Form1.tgMainSupplier.setfocus;
   end;
end;

l

309

(18 replies, posted in General)

Adam and wenchester21,
I updated the app to include id's. The question becomes what constitutes a duplicate. Obviously if an id exists in the table then it is a duplicate. This would be the case if you are using the export out of this app and importing back in. However, I have allowed for records being created in the csv file outside of MVD, in which case the id would be blank. With this scenario the app checks for duplicates for all fields in the csv record against the table record. I have not done extensive testing. Just don't have the time right now. If you find something broken, let me know, but it may be a couple of days till I can get to it. Of course, if anybody else wants to step in, I'm ok with that.

310

(18 replies, posted in General)

Wenchester21,
Yes, you're right. That's why I asked Adam what the purpose of exporting the entire database to a csv file. If it's for backup purposes, then the app needs to be changed to incorporate the id's in each table. Usually exporting to and importing from processes are built to interact with third party software and then it's typically only certain tables that are involved. I will update the app to include id's, which should take care of your foreign key error.

311

(18 replies, posted in General)

Adam,
Are you sure you are importing a csv file which was exported from the new app? It won't work with an old csv file. It seems like it must have worked for Wenchester21 with your sample db. If you want, upload your SQLite.db, if it's not too large, and I'll try it here.

312

(18 replies, posted in General)

Adam,
I had a chance to look at your project. I'm curious as to what is the purpose for exporting the entire database into a single csv file.


I took a slightly different approach but still using some of the concepts which Mathias suggested. In the attached project I coded it in such a way that you do not need to manually put in SELECT or INSERT statements for all your tables. and fields. The script will automatically retrieve all tables and columns within each table and build a single csv file for exporting.


As far as for importing, I had to create header lines for each table in the export procedure in order to distinguish between tables when reading the single csv file during the import process.


I used  a different process for checking duplicates when importing. The import process will do an SQL SELECT to see if the record exists in the respective table. It checks all fields (except id) against the database table for equal values.


You should be able to transport the import-export scripts to any project. It's not dependent on specific table definitions. However, keep in mind that images really cannot be copied to csv files. Hope this helps.

313

(12 replies, posted in General)

I had some time to look at your project. See attached for fix. One thing to understand, calculated fields are NOT real database table fields. They are primarily used in MVD for things like tablegrid columns. You cannot use them in SQL SELECT statements because they are not actual fields. Therefore whenever you need to construct an SQLQUERY you need to basically replicate the calculated field statement inside the SELECT of the Query.

314

(4 replies, posted in General)

Chances are that you forgot to include the new field in the list of fields to save in the SAVE ACTION of the form.

315

(5 replies, posted in Script)

Just remove all references to the dialog and replace LoadFromFile with hard coded file name. See below:

procedure frmMain_Button4_OnClick (Sender: TObject; var Cancel: boolean);
var
   userVar, modeVar : String;
   DateVar, TimeVar : Extended;
   sl: TStringList;
   arrStr: array of string;

   i,c: integer;
begin
          sl := TStringList.Create;
          sl.LoadFromFile (ExtractFilePath(Application.Exename) + 'YourFile.csv');


          c := sl.Count - 1;
          for i := 0 to c do
          begin
               arrStr := SplitString(sl[i], ';');

               // Nombre
               if arrStr[0] <> '' then arrStr[0] := ''''+ ReplaceStr(arrStr[0], '''', '''''') + ''''
                   else arrStr[0] := 'NULL';

               // 1er Apellido
               if arrStr[1] <> '' then arrStr[1] := ''''+ ReplaceStr(arrStr[1], '''', '''''') + ''''
                   else arrStr[1] := 'NULL';

               // 2do Apellido
               if arrStr[2] <> '' then arrStr[2] := ''''+ ReplaceStr(arrStr[2], '''', '''''') + ''''
                   else arrStr[2] := 'NULL';

               // CI
               if arrStr[3] <> '' then arrStr[3] := ''''+ ReplaceStr(arrStr[3], '''', '''''') + ''''
                   else arrStr[3] := 'NULL';

               modeVar := 'Importado';
               userVar := inttostr(frmLogin.cbLogin.dbItemID);
               DateVar := Now;
               TimeVar := Time;

               SQLExecute ('INSERT INTO student (firstname, lastname, surname, ci, pestado, pparticular, mestado, mparticular, ujc, cdr, pcc, feu, fmc) VALUES ('+ arrStr[0] +','+ arrStr[1] +','+ arrStr[2] +','+ arrStr[3]+', 0, 0, 0, 0, 0, 0, 0, 0, 0);');

               SQLExecute('INSERT INTO registro'+
               '(dateadded, timeadded, firstname, lastname, surname, ci, mode, id_users) '+
               'VALUES("'+DateToStr(DateVar)+'","'+TimeToStr(TimeVar)+'",'+ arrStr[0] +','+ arrStr[1] +','+ arrStr[2] +','+ arrStr[3] +',"'+modeVar+'","'+userVar+'")');

               frmMain.Label22.Caption := IntToStr(i+1) + ' of ' + IntToStr(c+1);
               Application.ProcessMessages;
          end;


          UpdateDatabase('student');
          UpdateDatabase('registro');
          sl.Free;
          frmMain.TableGrid1.dbUpdate;
          frmMain.TableGrid2.dbUpdate;
          frmStaticsUser.TableGrid2.dbUpdate;

end; 

316

(2 replies, posted in SQL queries)

Mathias,
Did you try this:

SQLExecute('ATTACH DATABASE ''Old_Db.db'' as ''Old''');
    SQLExecute('PRAGMA Old.foreign_keys=OFF');

317

(4 replies, posted in General)

tcoton,
Not sure how that is possible. If you remove the inttostr() on the dbitemid from David's example above, you will get an "Incompatible Types" error.

318

(2 replies, posted in General)

procedure frmMain_ClearButton_OnClick (Sender: string; var Cancel: boolean);
begin
    frmMain.TableGrid1.ClearRows;
    frmMain.TableGrid1.Columns[0].Footer.Caption := '0';
end;

319

(4 replies, posted in General)

David,
Id's are integers. dbitemid references the id in a tablegrid and is an integer. SqlExecute needs a string for the SQL statement. That's why the dbitemId needs to be converted to string  with the inttostr() function inside the SqlExecute statement.

SQLExecute('UPDATE Staff SET Location = "Away" where id =' +inttostr(form1.tablegrid1.dbItemID));

SqlValue can also be used in place of dbitemId. It is already converted to a string and no need to use inttostr() function:

SQLExecute('UPDATE Staff SET Location = "Away" where id =' +form1.tablegrid1.sqlvalue)

;

Hope this helps.

320

(4 replies, posted in General)

David,
See if the following works for you


procedure Form1_EditButton_OnClick (Sender: string; var Cancel: boolean);
begin
    If SqlExecute('Select Owner From yourTable where id = ' + Form1.TableGrid1.sqlValue) = 'System' then
       Begin
         ShowMessage('System record, cannot open');
         Cancel := True;
       End;
end;

Or you can also hide or disable the edit button when a row is selected that is a system owner record. The following is for a click on a row.

procedure Form1_TableGrid1_OnCellClick (Sender: string; ACol, ARow: Integer);
begin
    If SqlExecute('Select Owner From People where id = ' + Form1.TableGrid1.sqlValue) = 'System' then
      Form1.EditButton.Enabled := False else Form1.EditButton.Enabled := True;
end;

321

(24 replies, posted in General)

Adam,
Your project is fixed. However, you can only run it one time. If you try running it a second time, you will get duplicate component errors. So you need to comment out the SqlExecute lines between Begin and End after running it the first time. I think Mathias had some sort of versioning process and he could put those SqlExecute lines inside an If statement so it would only execute those lines if there was a different version.


You may want to consider creating a separate project just to upgrade the database in question. You can place the SqlExecute statements within the Begin and End of the upgrade project.That's what I do when there is an upgrade to the database. You will need to change the settings.ini file in the upgrade folder. There needs to be a "server=" line after the DBMS=SQLite entry to point to the database to be upgraded.

322

(24 replies, posted in General)

Adam,
If you are placing the SQL script inside an MVD project script, then you need to place the SQL scripts inside MVD SQLExecute commands.
SqlExecute('Create....');
SqlExecute('Insert.....');
SqlExecute('Drop......');
SqlExecute('Alter......');

323

(5 replies, posted in General)

Corrected lines are as follows:



Form1.Width := Form1.Width - Form1.Panel1.Width;

Form1.Width := Form1.Width + Form1.Panel1.Width;

324

(16 replies, posted in General)

Adam,
Yes you can use it for any memo field. In fact you can use it for any control in any form if you want. The values inside the brackets [ ] can be any value you want. I elected to use the ?form.control" name for easier readability. Whatever value you use just make sure that your font button OnClick procedure has the same value and the OnShow procedure for the control LoadFont has the same value.


There are usually more than one way to do things in MVD. I'm glad Dimitry shows other ways of doing things especially when it may not be obvious to some or hasn't been exposed previously in the forum.  It's always beneficial to me to see other ways.


As far as your lines inside memo fields, using a pixel based elastic line, as you put it, is not an option in memo fields in it's current state. When Dimitry introduces an RTF type memo fields, then maybe you'll be able to use this type of line. For now you're stuck with dashes or underscores.

325

(16 replies, posted in General)

Adam,
Attached is a sample use of an ini file to store fonts for controls.


Issues you need to address when inserting a full line across a memo field is how many dashes you need to produce for the width of the memo field. For each font/font size (and there are a lot) you need to know how many pixels are needed for one dash, then do a calculation utilizing the pixel width of the memo field, then do a loop to propagate the number of dashes. What makes it worse is if you place multiple lines throughout the memo field and then change the font of the memo field, you would need to go back through the memo field and retrieve all the dash lines and recalculate and re-propagate all the lines. There are a lot of fonts and font sizes. I just don't see that it would be worth the effort. I would simply use a smaller number of dashes like 10 or 20 as suggested. Then it will not matter what the font/font size is, unless you change the font size to something extraordinary like 72.


Hope this helps. Happy New Year to you too!