Jump to content

Columbo

Members
  • Content Count

    99
  • Joined

  • Last visited

Posts posted by Columbo


  1. 2 hours ago, Stano said:

    While this is a simple case and serves to teach, I do suggest one change there. Let it be as it should be.
    Create a TDataModule and put a FireDAC on it:

    • WaitCursor
    • Connection
    • Transaction

    The TFDTable-s in the whole project will connect to the DB using MyDataModule.MyConnection.
    The appropriate code from the form will also be moved to the TDataModule.
    I didn't want to write this by the shovelful. Since you didn't get it, here it is exactly:
    if TableDino.Locate('record', iSelect, []) then
    As you can see, I'm not searching by text, but by number. This is always faster and more certain. 

    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

     

     


  2. 5 hours ago, Gary said:

    Setting designtime components can be very helpful, try this:

     

    Open the connection and table.

    Right click table and select FieldsEditor...

    Right Click FieldsEditor and select AddAllFields 

    Notice the field objects are added to the form definition (tblPLifename)

    Click the dropdown of the FieldName on your DBEdits and notice you have a list to choose from, no typing in the field name where simple typo can derail you. Also you can now do this:

    No more tblPLife.FieldByName('name').AsString

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


  3. 27 minutes ago, Gary said:

    Your final project crashes on my computer, it will only run on your system! Reason is a common mistake that has bitten me many times. Your Database path is still hard coded to your system.

     

    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?

     

    Quote

    Congratulations on your first project, and I have to say it's a beauty. Most first projects are dull and boring.

    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. 🙂


  4. Hi Stano,  I tried you suggestion:

    Quote
    
    if TableDino.Locate(name, iSelect, []) then   //Had to change TableDino to tblPLife
      ShowMessage('Success')
    else
      ShowMessage('Issue');

     

    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.


  5. 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;
    
    

     


  6. @Stano, I appreciate the critique.

    Quote

    Throw out that maximized window. We already "require" it for two. You've got a picture of why at the end. It's for illustration purposes only.

    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.

    Quote

    Now this is premature, but you get the point.
    Table "dino":

    • everything should be capitalized
    • name DINOS 

    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.

    Quote

    Record lookup:

    • Users are used to searching alphabetically
    • you have entries written "randomly" 

    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.


  7. 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.


  8. 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? 

     

     

     

     


  9. 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.

    Quote

    You have a misunderstanding of Delphi list controls. Nearly everything in Delphi is zero indexed.

    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.


  10. 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.


  11. 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.


  12. 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:

    Quote

    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. 

    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.

     


  13. Hi Stano, 

    Quote

    I've opined that you should get rid of your DBNavigator altogether.

    I thought you said to use DBNavigator?

    Quote

    You need to use what is there. DBNavigator takes care of the button control automatically.

    Maybe I am misunderstanding what you are recommending?

     


  14. Thanks Stano. 

     

    Quote

    You're supposed to use the DataSet.Locate() function in SearchBox.OnChange(?). Or another appropriate event

    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.

     


  15. 23 hours ago, Gary said:

    How is all working fine different than compiled?

    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!

     

     


  16. 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.

     


  17. 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!

     

     

     


  18. 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.

     


  19. I changed all of the TDEdits to TDBEdits, set the DataSource and DataField and the DBNavigator is working now as it should however, that has created another problem.  As mentioned in one of my previous posts, the variable sName holds the name of the dino to search for in the database and I have images in 2 folders called dino_images and dino_size. The images have the same name as the name in the variable sName.  The image is loaded using LoadFromFile with the path to the image folder and whatever name is in sName.  The problem now is,  if I type a name into the search box, the record and the images are displayed as they should but,  if I use the DBNavigator to move to the next or previous record, the all of the TDBEdits are updated but the images are not. That is because the DBNavigator is not using my procedure to get the record along with the images.  I'm not sure how or where to edit the DBNavigator code to fix this.

     

    I have a TDBEdit that displays the record number however,  I just noticed that if I type a name into the search box the record is found and displayed.  If I then press next or previous in the DBNavigator, the record number is incorrect.  When the program first starts it pulls and displays record 1.  If I then type a name into the search box it gets that record and displays the proper record number, example record 9. If I then press next in the TDBNavigator it displays the data for record 2.  The same reason that the images do not change,... not using my procedure.

     

×