1 (edited by CDB 2020-02-23 12:16:42)

Topic: Formatting problem

I have a number which will always be 7 digits wide. It is a Part Number.


I am getting a 'conversion' error when I retrieve the textbox contents (9999999) using sqlValue. The error I get is '''9999999''' is not a valid integer value.
 

If I use TEXT instead of  sqlValue I still get the same error, but the value is shown as 20.


The aim of this code is to take the contents of a pre-filled set of text boxes and add as a new record back into the database. In other words, a previous order is reissued but now with the current date of issue.


In fact is their a simpler way to achieve what I'm trying to do?


procedure frmTechOrderDetails_btnReorder_OnClick (Sender: TObject; var Cancel: boolean);
var
    dbSuppID, dbTechID,dbQty:integer;
    dbPNum: cardinal;
    dbPart,dbPCode:string;
begin
    dbPart:= frmTechOrderDetails.edtPartDescription.sqlValue;
    dbPCode:= frmTechOrderDetails.edtPartCode.sqlValue;
    dbPNum:= strToInt(frmTechOrderDetails.edtPartNumber.sqlValue); //THIS IS THE CODE FAIL
    dbQty:= strToInt(frmTechOrderDetails.edtQty.sqlValue);
    dbTechID:= SQLExecute('SELECT id FROM techname WHERE tech = "'+ frmTechOrderDetails.edtTechName.text + '"');
    dbSuppID:= SQLExecute('SELECT id FROM supplier WHERE sup_name= "'+ frmTechOrderDetails.edtSupplier.text + '"');
  sqlExecute('INSERT INTO requests (id_techname, part, requestdate, id_supplier, partCode, partNumber, quantity) VALUES ("+dbTechID+",'+dbPart+',(DATE("now")),"+dbSuppId+",'+dbPCode+',"+dbPNum+","+dbQty")');

//debug message
showmessage('TechID = '+ intToStr(dbTechID) + ' SuppID = ' + intToStr(dbSuppID)+ 'Part name '+dbPart);
//end debug
end;
Post's attachments

Attachment icon cdb partsrequest.zip 351.95 kb, 292 downloads since 2020-02-23 

On a clear disk you can seek forever

Re: Formatting problem

I've just realised that the problem lies in the strToInt function.

I think that the easiest way out of my dilemma is to change the database to expect a 'TEXT' entry, and then use the Numbers only property set to True, and an entry mask of 7 digits.

That should solve the problem, no?

On a clear disk you can seek forever

Re: Formatting problem

See attached, I made changes to your database and the controls on the form for it to work.
Let me know of any challenge

Post's attachments

Attachment icon cdb partsrequest.zip 18.83 kb, 318 downloads since 2020-02-23 

@thezimguy

Re: Formatting problem

Hello CB, the zinguy

By the way, nothing to do with your problem (that the zimguy solved), only to make the program more user-friendly, you can hide the btnSearch (Find) button and fill the Increm.Search property of edtSearch (Editbox) with btnSearch.

The incremental search will be activated and the display of the searched item quickly displayed.

But you may have already thought about it?

JB

Re: Formatting problem

@thezimguy,

Thank you, I like your idea of turning two of the edit boxes into comboboxes, and  your 3 lines of code is neat and succinct.


Two questions though:


1. What does the extra foreign key 'techID1'  actually do?  I've looked at the constraints for that key versus the original techID, but can't see the advantage.


2. I've never understood what the property 'dbGeneralTableId'  actually does.


@Jean.brezhonek,

I was aware, and have been trying to decide which option to take. I think the hidden button way is probably the way to go.   Sadly when a search is performed, I lose the double click action on the grid - in other words it doesn't do anything. But i can live with that until I work out a workaround.

On a clear disk you can seek forever

Re: Formatting problem

Hello cdb

To keep editing a recording by double clicking on a cell in the grid, you must put an (hidden) EDIT button which will expand this recording to an appropriate form.

JB