276

(6 replies, posted in General)

I don't think it is, MarkoS, at least I haven't found a way to do that.


As an aside you will also find that 'sending' a component to the back doesn't work for some things, like making an edit box or button visible by sending a panel to the back, if you decide to use a panel or group box after placing components on the form.

Is it possible to use the above function when using MVD to automatically post data to the database?

I understand how to do it with an 'on_click' procedure and manually write the SQL using SQLExecute, but can it be called somehow and still have MVD automatically add or save  a database entry?

Try the amended code below.


('select distinct b.vhod_data, c.sprav_zapros, a.data, a.numer' + 'from sprav a join zapros b on a.id_zapros=b.id join sprav_zapros c on a.id_sprav_zapros=c.id where b.id ="'+ intToStr(idzapr)+'"') 

I'm interested in the undocumented property you have used EHW  - dbDon'tResetID, I can't find it anywhere or in the help or auto complete selection.

280

(6 replies, posted in Russian)

Andrei

Try

frmOrg.TabSheet3.TabVisible := False;

Thank you for putting me on the right track ehwagner,

Your help is gratefully received.

Thanks ehwagner,

That has solved the -1 problem, it hasn't solved why clicking on the grid fills out all the correct items apart from Category.

I shall try and work out why this one field is not behaving.

Hi ehwagner,


Attached is my project so far that has the problem of returning -1 when the tablegrid is clicked for the first time.


From frmMain click on the Part Maintenace tab and then on  the EDIT button. Six items will appear in the table grid.


Click on any of the five items and the text boxes on the left will be filled out waiting to be edited if needs be.


I have a further problem - I cannot get the items in the part_categories table to match the foreign key in the products table.  No matter what I try the part category is not in sync. The database does have the correct entries in the products table.

You will see that in the OnCellClick event for the table I've put in some debugging code.

The part categories I should be seeing in order of the products listed in the table grid is:

A2D/Scalar card    ID 7
A2D/Scalar card    ID 7
A2D/Scalar card     ID 7
Power Supply        ID 6
Component            ID 3
Component            ID 3


I'm using v6.3.


PS: I've just realised this build does not have the foreign key in products - I'd taken it out while sorting  out a DB corruption.

284

(5 replies, posted in General)

Unforgettable,

Do you mean as you type into the edit box it auto completes out the text, like a browser when typing in a URL can do?

285

(26 replies, posted in General)

Unforgettable,

Have you changed the form names for the two table grids?

For example if your form is named frmSales    you would need to change FORM1.tgSales.  to frmSales.tgSales.

When you get the red error line what error message is at the bottom of the IDE ?

I have a table grid which is filled using a SQL statement - purely because the data comes from multiple tables.



The table is read only. The idea is that via scrolling or a search, an item is found, and when clicked on, the row appears in a number of text edits ready for editing.



My first attempt in the OnCellClick procedure was:


frmEditPart.edtEditDescription.Text := sqlexecute('SELECT description FROM productsupplier WHERE id=' +intToStr(frmEditPart.grdEditPart.dbItemID));


Now, that produces a -1 on the first click on the cell, but works correctly after that.


So I experimented with :


frmEditPart.edtEditDescription.Text := sqlexecute('SELECT description FROM productsupplier WHERE id=' +(frmEditPart.grdEditPart.sqlvalue));


That produces a NULL on the first click and then works as expected after that.

I worked around the problem by


frmEditPart.edtEditDescription.Text := frmEditPart.grdEditPart.Cells[1,Arow];


However, I'm puzzled as to why the previous two attempts produce this NULL.

I've had some further thoughts. Using DB Browser or SQLite studio you could make the columns you need to check for duplicates as UNIQUE the database should then complain everytime you enter a duplicate value.


This also might work in a SQL statement:


dbcheck:string;


dbcheck:=SQLExecute(SELECT * FROM your_table WHERE your_column IN (SELECT your_column FROM your_table WHERE your_column = "your duplicate value here"));


This returns duplicates


So the Pascal would be


If dupcheck = dbcheck
do something here.

An alternative on the above is to change IN to NOT IN , this would then return all records but the duplicate.

The Pascal would then change to

if dupcheck <> dbcheck .

OK, I had written an answer and then clicked the back button on my browser and lost it! sad

I would do this:

Have an OnCellDoubleClick event  on your tablegrid.

procedure Form1_tablegrid1_OnCellDoubleClick(Sender: TObject; ACol, ARow: Integer);
var
dupcheck:string;
begin
dupcheck:= Form1.tablegrid1.cell[ACol, ARow];

..//dupcheck will contain the contents of whichever cell you have clicked on.
..
..
end;

See ehwagners SQL code for duplicate checking here   http://myvisualdatabase.com/forum/viewt … p?id=6219.

This means you have to double click on your cell after entering data for the check to fire, it might be eaiser to get the double click to open an entry form and then use ehwagners code.

Warning! I seem to always go for the complicated way of doing things, so the experts here may have a simpler answer.

Are you needing to check just one cell/ column in the grid or the complete row for duplicates?

Thank you both.

@Derek,  It never occurred to me to use a hidden save button.

@ehwagner, It just goes to show how much better everything works when using the correct 'grammar' for statement.

I have just had a thought, maybe I don't have to use the 'where' clause at all, as both tables should be in sync as far as a new record is concerned. Though for belts and braces it is probably better to ensure they are using the same record ID.

I shall go and try that immediately - thanks Derek.

Being too clever for my own good.!  I need to save an entry form to two different tables in the database.

So, I have used the inbuilt SAVE mechanism for one table and then in the 'after_click' event (which I'm using as a sort of trigger SQL) I have the follwoing code.

procedure frmMain_Button3_OnAfterClick (Sender: TObject);
var dbid: integer;
begin
    dbid := frmMain.Button3.dbGeneralTableId;

    sqlexecute('INSERT INTO productSupplier (supplier_part_number) VALUES ("'+frmMain.edtSupplierCode.text+'") WHERE ID = '+IntToStr(dbid));
    sqlexecute('INSERT INTO productSupplier (description)VALUES ("'+frmMain.edtDeascription.text+'") WHERE ID = '+IntToStr(dbid)+')');
    //sqlexecute('INSERT INTO productSupplier (notes)VALUES ("'+frmMain.memPartNotes+'") WHERE ID = ("'+dbid+'")');
end;

Neither format of the SQL statement works as shown above - I get a 'NEAR WHERE' error message.

Ignore the image box picture, I got fed up searching for the correct picture so just selected the first one I came to on my PC.

I have a series of edit boxes and what I would like to do is as I press  the 'enter' key, the next edit box automatically gets focus. So basically using the enter key instead of a tab key.


I'm wondering of there is an easier way than producing multiple 'ONKEYxxxx' events for each edit box.


I'm using a panel and page control on a form, so making the forms' KeyPreview := true and then


if key=#13 then
perform(wm_nextDlgCtrl,0,0);
end;

doesn't work.

295

(187 replies, posted in General)

If at all possible I think a 'lock' property at design time for components on a form as in Delphi would be useful.

Hi Derek,

Just a quick question, how did you make the drop down boxes embed into the table grid on the Supplier parts X-ref tab?

297

(16 replies, posted in General)

ehwagner wrote:

CDB,
it must have been introduced either in 6.3 or 6.4. Anybody who is on 6.2 or below must use "User.Username".

I'm using 6.3.

298

(16 replies, posted in General)

Thank you Dmitry.


I've attached the modified script file for others.

Obviously it will either need to be renamed as 'script.pas' or a 'uses' clause will need to be added to the main script file of the project.


Amended file name to take into account ehwagner's comments below.

Hello Derek,

That is well on the way to what I'm trying to do. Thank you very much.

I'm determined to work out why my schema doesn't work once I add the Technician name into the grid.

I'll have to try it out in mySql to work out why adding the tech name creates duplicate entries.

300

(16 replies, posted in General)

Hi ehwagner,


I can't get your example to compile.  It can't find the reference to User.Username at line 9.

I tried altering it to _user.username but it didn't like that either.

Is the User.username referring to the login form or to the _user.username table?