Jump to content

Columbo

Members
  • Content Count

    99
  • Joined

  • Last visited

Everything posted by Columbo

  1. Columbo

    Help with Query at run time

    My first program with Delphi 11 Community is coming along slowly but surely. I have set up a database, SQLite, and I am able to connect to it and to the table. I have a number of TEdit controls, (which I call fields), a Memo and a TabbedSheet containing TImage controls on my form. ( the form is frmDino). This is the point where I need help. I would like to be able to set up a query that, using a variable containing a name, will pull one record from the database, based on a match between the name in the variable and the ‘name’ column in the database and then populate the fields (TEdits) with the data from the record found. All names in the database are unique. The first TEdit on my form is edtName and if I can populate this field I think I can do the others. I have searched the internet and found a number of query examples but they are all using queries set up at design time. Can anyone give me example code of a query that is set up at run time as explained in the above paragraph? Comments in the code would be helpful. The database is called dino.db and the table is called ‘dino’. The column in the database to search is called ‘name’. The variable containing the name to search for is called sName. Any help greatly appreciated.
  2. Columbo

    Help with Query at run time

    Thanks Stano, I took your advice and sorted the List alphabetically. Previously the items in the Listbox was in the same order as the database except that, record 1 in the database was position 0 in the Listbox. When a record was selected I added 1 to the position in the Listbox and that corresponded to the correct record in the database. When the Listbox was sorted, the positions in the Listbox did not align with the record number in the database, so I used the name selected in the Listbox and searched the name field in the database. That works fine. If the Listbox is used there will not be any typo errors. Here is a link to the sorted version. Sorted Version
  3. Columbo

    Help with Query at run time

    Thanks Gary, I will store this away for future use.
  4. Columbo

    Help with Query at run time

    Thanks Gary, I will store this away for future use.
  5. Columbo

    Help with Query at run time

    Ok, I was just going to send another link to the latest fixed version. I won't have to now. 🙂 Thanks for all of your help and encouagement Gary. Merry Christmas and hope you have a great 2024.
  6. Columbo

    Help with Query at run time

    I thought that I had fixed that. I used: [procedure TfrmDino.FormCreate(Sender: TObject); //Form creation begin conPLife.Params.Database := IncludeTrailingPathDelimiter(TDirectory.GetCurrentDirectory) + conPLife.Params.Database; conPLife.Connected := True; tblPLife.Active := True; lbxData.Visible := False; end; In the conPLife under Params I have Database set as dino. Should I clear that and do it in the code? Thanks Gary. It is a program that I wrote a few years back and I used it as a learning process for Purebasic and then again in Python so I now have 3 different versions of this program. 🙂
  7. Columbo

    Help with Query at run time

    That was it! I should have caught that the quote was missing. I must be blind. Actually I am going for cataract surgery next month. lol Thanks Gary.
  8. Columbo

    Help with Query at run time

    Hi Stano, I tried you suggestion: The app runs but as soon as I select a name in the Listbox I get an error. [FireDAC][Stan][Eval]-100 Column of function [frmDino] is not found.
  9. Columbo

    Help with Query at run time

    Merry Christmas to all. I am trying to make a change to the app to use the Locate() Function but I am having a problem with the proper syntax. My understanding from what I see in the docs and other data, it is Locate(name of field, what to find, []); but I keep getting an 'Undeclared Identifier Locate' error. I tried using tblPLife.Locate(name of field, what to find, []); but while the Undeclared Identifier error goes away and the app runs, as soon as I select an item in the Listbox I get a 'Column or Function not found' error. Here is the code that I was trying: procedure TfrmDino.lbxDataClick(Sender: TObject); iSelect: Integer; begin If lbxData.ItemIndex > -1 then begin iSelect := lbx.ItemIndex; sName := lbxData.Items[iSelect]; tblPLife.Locate(name, sName, []); //name is the column and sName is what I want to find. end Else ShowMessage('Nothing Selected'); end;
  10. Columbo

    Help with Query at run time

    @Stano, I appreciate the critique. The image is not large enough for me to read it properly so I'm not sure what is wrong with the app being maximized when run. I am not trying to be nasty or anything but what difference does it make if it is in lowercase? Just curious as to the reasoning. They are not really random. They are in the order of the era that they lived starting from when life first evolved up to when humans arrived.
  11. Columbo

    Help with Query at run time

    I made a couple of changes to my application and I think it is ok now. Not the best coding but it works and the improvements should come with further practice. There are a few things in Delphi that bugs me, like making it such a task to get rid of the Titlebar and the Delphi icon. I have given up on that for now but the app looks terrible with a brown and cream color scheme and a Blue titlebar. If you could at least change the color from blue to brown to match the rest of the app it would be better but that seems to be impossible as well in Delphi. But, I sincerely thank everyone for their help and patience. You can get the finished version here.
  12. Columbo

    Help with Query at run time

    Wow! It's getting more and more confusing. Anyway, I think that I have it working now however, there is still one problem that bothers me and that is the titlebar. I want my header image to be at the very top when the application runs. In design mode it is at the very top and no Delphi titlebar. When I compile it to an .exe the Delphi titlebar appears at the top with the Delphi logo and my header image is pushed down 30px. Anyway to get rid of the Delphi titlebar?
  13. Columbo

    Help with Query at run time

    Jon, In my code everything was working but as soon as I set connected to 'False' and do a build, the .exe can't find the images. If I go back and change the 'Connected' to true and try to run it from within design mode it can no longer find the images in design mode either. Also, when using your code, when I select a animal from the Listbox it is not getting the correct record. If I select record 9, I get record 8. I did understand that the index starts at 0, and that is why I used the iSelect := lbxData.ItemIndex +1; so iSelect would match the record number in the databse. In the database, Cephalaspis is record number 6. Using your code, if I select Cephalaspis in the Listbox I get record number 5, Megalograptus.
  14. Columbo

    Help with Query at run time

    Hmmmm, I checked the params in the TFDConnection component and it had the full path to the database so it is hard coded. I tried putting just the database name (dino.db) thinking that it would look in the current directory for the file but doesn't work. It then flags an error that my images cannot be found as well. The path for the images is dino_images.Picture.LoadFromFile('dino_Images\ ' + sName + '.jpg'); dinoSize.Picture.LoadFromFile('dino_Images\ ' + sName + '_size' + '.jpg') so it should be able to find them from in the current directory. I zipped the entire project but it is too big to attach here. Try this link.
  15. Columbo

    Help with Query at run time

    All done! Seems to be working as it should. I have attached a link so you can see what I was doing. Given that it is my first application in Delphi there is probably room for a lot of improvement but it was intended as a learning project. Also, I don't know what screen resolution you are using but this app was for 1280 x 720. I removed the link for now.
  16. Columbo

    Help with Query at run time

    I suppose there has been some kind of confusion. I am probably not making myself clear in my posts. I had created my own buttons and they worked well as did my search box. Then you said that I shouldn't make my own buttons and that I should use the DBNavigator. Gary recommended that I should take your advice and so I agreed. My response to Gary was: So I am now working on making changes to the application to use the DBNavigator. It is working as far as moving back and forth through the records but it is not loading my images. The images are loaded using the contents of the TDBEdit (dbeName) after the record has been retrieved but I am not sure what DBNavigator uses to retrieve the record. I am assuming that it is incrementing or decrementing the record number. I am currently trying to figure out how to resolve this image issue. I will work on that today.
  17. Columbo

    Help with Query at run time

    Hi Stano, I thought you said to use DBNavigator? Maybe I am misunderstanding what you are recommending?
  18. Columbo

    Help with Query at run time

    I am going to try to see if I can make the changes to the application. I will wait just a bit longer to get you the link so that you can get the DBNavigator version if I am successful in implementing the changes.
  19. Columbo

    Help with Query at run time

    I was just looking at the Locate function. I will check that out DataSet, along with T(FD)Table and T(FD)Query. Thanks again Stano.
  20. Columbo

    Help with Query at run time

    Thanks Stano. I was not aware of the DataLocate function. I'll look at it and see how it works. Maybe I can do a version of the app using that.
  21. Columbo

    Help with Query at run time

    Guess your right Gary. I had been under the impression that after the coding of an application you had to compile it into a distributable package that used all of those other files that are created in the project but I see now that I can just take the .exe file along with my DB and image files and it woks. I was going to send you a copy of the app but it is 10,600KB. I couldzip it and upload it to one of my web sites and send you a link to download it? Cheers!
  22. Columbo

    Help with Query at run time

    Thanks Stano, I have it working now since I created my own buttons. The buttons and the search box are working fine. I also disabled the btnStart and btnPrevious buttons if it is on the first record and the btnLast is disabled if it is on the last record. All working fine now. I am going to look at how to compile it now.
  23. Columbo

    Help with Query at run time

    Hi Gary, I have it working now. I created my own buttons for First, Previous, Next and Last. They are working well and no problems using either the buttons or the search box. They both work with each other. A few more touch ups and I'll be ready to try to compile it. I need to look up the docs on compiling though. Cheers!
  24. Columbo

    Help with Query at run time

    Ok, Thanks Gary.
  25. Columbo

    Help with Query at run time

    Thanks Gary, I have fixed the problem of getting the images to display but I am still having a problem with the TDBEdit, (dbeRecno), getting the proper record number. In the database, the first column is 'record' and it is and Integer value. If I use the prior or next buttons on the DBNavigator, it works fine and the record numbers display properly in the dbeRecno. However, if using the DBNavigator I advance to the 6th record and then enter a name in the search box, (example Climatius), it will jump to record number 9 which is correct. If I then press the Prior button on the DBNavigator it will jump to record 5 instead of 8. Again, because the search box is using my procedure instead of the DBNavigator procedure. I have played with this the whole day today and I can't figure out a solution. I'm going to take a break before torturing myself further.
×