Jump to content

Columbo

Members
  • Content Count

    99
  • Joined

  • Last visited

Everything posted by Columbo

  1. Columbo

    Help with Query at run time

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

    Help with Query at run time

    Thanks Remy, Sorry for the late response, I was out of town for the weekend. Prior to leaving for the weekend I had figured out how to have the first record displayed when the program is started. I was also able to set up my search box so that it didn't matter if the user entered a name in upper case or in lower case or a combination of both it will still find the record. I need to look for some info on a "LIKE' statement or something similar. Many people don't know how to spell the names of some of the dinosaurs in the database so if they do misspell a name it should get the record with the name closest to that entered into the search box. Stano also pointed out that I should be using DBEdits instead of TEdits. I'll try doing that tomorrow now that I am back home. Everyone on this forum have been very helpful and I do appreciate the help and the patience shown while I try to get a grip on Delphi. My thanks to all.
  3. Columbo

    Help with Query at run time

    I was able to figure out how to display the first record on start up and it works well. My next problem is the DBNavigator. I placed a DBNavigator on my form and I am using only the BOF, Previous, Next and EOF buttons. My understanding is that when you place a DBNavigator on your form you set it's Datasource property to your Datasource. In my case my Datasource is Datasource1 and, of course, that is the only Datasource that is listed in the drop down menu for the Datasource property. I did that and ran the program but when I press the next button nothing happens. Actually, nothing happens when I press any of the buttons. Does it need something else set? I guess I could create my own nav buttons but using the DBNavigator seemed like the easiest way to do it.
  4. Columbo

    Help with Query at run time

    Thank you haentshman, I change that.
  5. Columbo

    Help with Query at run time

    Thanks yet again Remy. That is perfect! And BTW you had asked: The answer to that is that it is empty. I am just trying to figure that one out now because when the program is first run it pops up a dialog box saying that sName is empty. I want to retrieve record 1 and populate the fields when the program is first run. With all of the other stuff like loading the images and stuff I haven't had much time to think about it.
  6. Columbo

    Help with Query at run time

    Thanks Remy, I was going to add checks for EOF and BOF as well as 'If found...' but I wanted to first be sure that the program was finding the DB, able to query the DB and load the images as well. Once I was sure I could do that I was going to add the checks. You have been extremely helpful and I appreciate your time and patience.
  7. Columbo

    Help with Query at run time

    Ok, It seems to be working now however I do have another question about the images. I'm not sure as to how to word this is a manner that is clear but,... as i mentioned earlier, I have the TImage in a TabbedSheet. I load the dino image into Tab1 (Dinosaur), and the second image into Tab2 (Size Comparison). If I search a record, Tab1 is the selected Tab and the dino is displayed. If I click on Tab2 the size comparison is diaplayed, which is how it should be however, if I then search a new record, Tab2, the size Comparison is displayed first since that was the Tab being displayed just before searching a new record. The proper picture is displayed but Tab2 shows first Is there a way that whenever you search a record Tab1 is always displayed first?
  8. Columbo

    Help with Query at run time

    Ok, I think that I might have it working now. I'll do a little more testing to confirm it.
  9. Columbo

    Help with Query at run time

    Here is the code. unit Dinobase_u; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls, System.ImageList, Vcl.ImgList, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.DBCtrls, Vcl.Buttons; type TfrmDino = class(TForm) pnlTitlebar: TPanel; Image1: TImage; pnlHeader: TPanel; Image2: TImage; lblName: TLabel; edtName: TEdit; lblMeaning: TLabel; lblPronounce: TLabel; edtPronounciation: TEdit; edtPeriod: TEdit; lblPeriod: TLabel; edtMeaning: TEdit; edtMainGroup: TEdit; lblMainGroup: TLabel; pnlFooter: TPanel; Footer: TImage; edtSize: TEdit; lblSize: TLabel; edtLived: TEdit; lblLived: TLabel; edtDiet: TEdit; lblDiet: TLabel; edtFossils: TEdit; lblFossils: TLabel; memFactfile: TMemo; PLTabSheet: TPageControl; TabSheet1: TTabSheet; SizeComp: TTabSheet; dinoImage: TImage; dinoSize: TImage; conPLife: TFDConnection; tblPLife: TFDTable; DBNavigator1: TDBNavigator; Datasource1: TDataSource; edtRecno: TEdit; lblRecno: TLabel; BitBtn1: TBitBtn; FDQuery1: TFDQuery; edtSearch: TEdit; btnSearch: TButton; lblSearch: TLabel; procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure btnSearchClick(Sender: TObject); // procedure displayimages; private { Private declarations } public { Public declarations } procedure getdbrecord; end; var frmDino: TfrmDino; implementation {$R *.dfm} procedure TfrmDino.BitBtn1Click(Sender: TObject); begin Application.Terminate; end; procedure TfrmDino.btnSearchClick(Sender: TObject); begin getdbrecord; end; procedure TfrmDino.FormCreate(Sender: TObject); var img1: String; img2: String; begin WindowState := wsMaximized; getdbrecord; end; procedure TfrmDino.getdbrecord; //Get record procedure var sName: String; //holds name of dino record to retrieve img1: STRING; img2:String; begin img1 := sName + '.jpg'; img2 := sName + '_size.jpg'; sName := edtSearch.Text; FDQuery1.SQL.Text := 'SELECT record,name,meaning,pronounce,period,maingroup,size,lived,diet,factfile FROM dino Where name = :PName'; FDQuery1.ParamByName('PName').AsString := sName; FDQuery1.Open; //place data into edtName edtRecno.Text := FDQuery1.FieldByName('record').AsString; edtName.Text := FDQuery1.FieldByName('name').AsString; edtMeaning.Text := FDQuery1.FieldByName('meaning').AsString; edtPronounciation.Text := FDQuery1.FieldByName('pronounce').AsString; edtPeriod.Text := FDQuery1.FieldByName('period').AsString; edtMainGroup.Text := FDQuery1.FieldByName('maingroup').AsString; edtSize.Text := FDQuery1.FieldByName('size').AsString; edtLived.Text := FDQuery1.FieldByName('lived').AsString; edtDiet.Text := FDQuery1.FieldByName('diet').AsString; memFactfile.Text := FDQuery1.FieldByName('factfile').AsString; //displayimages dinoImage.Picture.LoadFromFile('D:\Delphi_11_Community\MyProjects\Dinobase\dino_images\' + sName + '.jpg'); //edtSearch.clear; end; end.
  10. Columbo

    Help with Query at run time

    Hi Jon, I have a 10 TEdits that I populate with info from the DB. I also have a TEdit that I use as a search box. When I type a name into the search box and press ENTER, it places the text, (the name to search for), into sName. sName is then used in the query to find the appropriate record and populate the other 10 TEdits. The image for that record has the same name as the name in sName. If I comment out the LoadFromFile line all of the other TEdits get populated and that would not happen if sName was empty.
  11. Columbo

    Help with Query at run time

    Hi weirdo12, Actually I tried something similar to that before. I assigned the path to a variable like so: imagePath := 'D:\Delphi_11_Community\MyProjects\Dinobase\dino_images\'+ sName + '.jpg'; but... had the same problem. I have the TImage in a TabbedSheet but that shoudn't have anything to do with finding the image file.
  12. Columbo

    Help with Query at run time

    Hi Jon, I have 10 TEdits that are populated with info from the DB. I have another TEdit that I use as a search box. When I type a name into the search box and press ENTER the contents of the search box is placed into the variable sName. If I comment out the LoadFromFile line and run the program all of the TEdits are populated. That would not happen if sName was empty. After the 10 TEdits are populated, I do the LoadFromFile using the same sName. I do not clear the variable sName before calling the LoadFromFile. The image that it looks for has the same name as the name stored in the sName variable. In other words, If I am searching for the name 'Anomalocaris', the image file that it should load is 'Anomalocaris.jpg'. here is my query code: Query.SQL.Text := 'SELECT Name, OtherFieldsAsNeeded from dino where Name = :PName';Query.ParamByName('PName').AsString := sName;Query.Open;edtName.Text := Query.FieldByName('Name').AsString;
  13. Columbo

    Help with Query at run time

    Hi Lajos, I'm still getting a problem loading the image. I have a TImage named dinoImage so using your suggestion I added: dinoImage.Picture.LoadFromFile('D:\Delphi_11_Community\MyProjects\Dinobase\dino_images\'+ sName + '.jpg'); When I run it I get am error saying 'Cannot load file. Image cannot be found '.jpg' The path is correct but it seems as if it is not adding the sName but only the ',jpg'. Suggestion?
  14. Columbo

    Help with Query at run time

    Thank you Lajos. That's great! I'll give that a try. I had already added jpeg to the uses but I was unsure as to how to use the LoadFromFile. Thank you so much.
  15. Columbo

    Help with Query at run time

    Thanks Remy, Stano pointed that out. I changed 'group' to maingroup at it is working now. I have a TEdit as a 'Search' box and a 'Go' button. I was able to figure out how to be able to use the button or to press the <ENTER> key to invoke the search and that works well now. My next step is to figure out how to load an image from a folder into a TImage control at runtime. The images have the same name as the variable 'sName' which is the pulled from the 'name' column in the record that has been selected from the DB. Example: sName + ".jpg'; // the first record in the DB would set the image name to 'Anomalocaris.jpg'. The image is located in D:\Delphi_11_Community\MyProjects\Dinobase\dino_images . I think that it is loaded with 'LoadFromFile()' but I have to see how to code that.
  16. Columbo

    Help with Query at run time

    Thanks again Stano. I must look to see a list of all of the keywords in Delphi. Yes, using DBEdit was mentioned before but I had spent a fair of time on the design and, at least for now, I didn't want to have to change everything. If I can get this working I will change them to DBEdits later. I know that it would probably be easier to do it now. Thanks again.
  17. Columbo

    Help with Query at run time

    During my learning process with this program that I am working on I have been able to figure out and resolve a number of errors but here is one that I am really stuck on. I have been working on pulling the data from my DB and filling in my TEdits with the data from the record. For testing purposes I am only working with 1 record. I pull the data from the database using: FDQuery1.SQL.Text := 'SELECT record,name FROM dino Where name = :PName'; FDQuery1.ParamByName('PName').AsString := sName; FDQuery1.Open; //place data into edtName edtRecno.Text := FDQuery1.FieldByName('record').AsString; edtName.Text := FDQuery1.FieldByName('name').AsString; This is working ok. Being a bit cautious I have been adding the columns 1 at a time and running the program after each addition to be sure there are no errors. There are 10 columns (fields) in the database which are: record, name, meaning, pronounce, period, size, lived, diet, fossils, factfile. Everything works perfectly except when I add the 'group' column and then it flags an error. If I remove that 1 column from the query all of the others work fine. The error that I am getting is: Dinobase_p [FireDAC][Phys][SQLite]Error: near 'group'; syntax error. I checked the column name in the database and it is correct. All that I am doing is adding the 'group' to the query the same as I did for the other 9 TEdits but as soon as I do,... ERROR! Here is my entire code: unit Dinobase_u; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls, System.ImageList, Vcl.ImgList, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.DBCtrls, Vcl.Buttons; type TfrmDino = class(TForm) pnlTitlebar: TPanel; Image1: TImage; pnlHeader: TPanel; Image2: TImage; lblName: TLabel; edtName: TEdit; lblMeaning: TLabel; lblPronounce: TLabel; edtPronounciation: TEdit; edtPeriod: TEdit; lblPeriod: TLabel; edtMeaning: TEdit; edtMainGroup: TEdit; lblMainGroup: TLabel; pnlFooter: TPanel; Footer: TImage; edtSize: TEdit; lblSize: TLabel; edtLived: TEdit; lblLived: TLabel; edtDiet: TEdit; lblDiet: TLabel; edtFossils: TEdit; lblFossils: TLabel; memFactfile: TMemo; PLTabSheet: TPageControl; TabSheet1: TTabSheet; SizeComp: TTabSheet; dinoImage: TImage; dinoSize: TImage; conPLife: TFDConnection; tblPLife: TFDTable; DBNavigator1: TDBNavigator; Datasource1: TDataSource; edtRecno: TEdit; lblRecno: TLabel; BitBtn1: TBitBtn; FDQuery1: TFDQuery; edtSearch: TEdit; btnSearch: TButton; lblSearch: TLabel; procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure getdbrecord; end; var frmDino: TfrmDino; implementation {$R *.dfm} procedure TfrmDino.BitBtn1Click(Sender: TObject); begin Application.Terminate; end; procedure TfrmDino.FormCreate(Sender: TObject); var img1: String; img2: String; begin WindowState := wsMaximized; getdbrecord; // Set image name img1 := 'Anomalocaris'; img2 := 'Anomalocaris_size'; //TImage.dinoImage.LoadFromFile(img1); //TImage.dinoSize.LoadFromFile(img2); end; //Add a procedure here to clear all TEdits, Memo and Pictures procedure TfrmDino.getdbrecord; //Get record procedure var sName: String; //holds name of dino record to retrieve begin sName := 'Anomalocaris'; FDQuery1.SQL.Text := 'SELECT record,name,meaning,pronounce,group,period,size,lived,diet,factfile FROM dino Where name = :PName'; FDQuery1.ParamByName('PName').AsString := sName; FDQuery1.Open; //place data into edtName edtRecno.Text := FDQuery1.FieldByName('record').AsString; edtName.Text := FDQuery1.FieldByName('name').AsString; edtMeaning.Text := FDQuery1.FieldByName('meaning').AsString; edtPronounciation.Text := FDQuery1.FieldByName('pronounce').AsString; edtPeriod.Text := FDQuery1.FieldByName('period').AsString; edtMainGroup.Text := FDQuery1.FieldByName('group').AsString; edtSize.Text := FDQuery1.FieldByName('size').AsString; edtLived.Text := FDQuery1.FieldByName('lived').AsString; edtDiet.Text := FDQuery1.FieldByName('diet').AsString; memFactfile.Text := FDQuery1.FieldByName('factfile').AsString; end; end.
  18. Columbo

    Help with Query at run time

    Thanks Stano.
  19. Columbo

    Help with Query at run time

    Thanks again Remy. Is there a list of hex colors somewhere in the net? If I were going to use a color like the dark brown that I am using in my program, I know that it is #502E0F or RGB(80,47,15) but how would I know that is $23F ? Thanks again.
  20. Columbo

    Help with Query at run time

    Thanks Gary, All of these TEdits are Read Only and I experimented a bit and found that I could prevent this by setting the AutoSelect property to False. Although I have a good start on this program I still have a long way to go. I will send you the finished program when it is done. Thanks for you encouragement. Cheers
  21. Columbo

    Help with Query at run time

    Apparently I still have one problem. When the TEdit (edtName) is populated the text is highlighted like it is selected. Is there a way to prevent this,... just normal text?
  22. Columbo

    Help with Query at run time

    @tgbs Thank you. I missed that and I believe that I now have it working.
  23. Columbo

    Help with Query at run time

    Thanks Remy, I you are referring to the setting of the font colors for the labels and TEdits, the colors that I need are not available in the font menu list and the only way that I could get the color that I want was to do it that way. I tried entering the custom color to the list but it wouldn't accept it. As tgbs pointed out, I hadn't assigned the name that I wanted to search for in the variable sName. I did that and I believe that it is working now. Thank you for all of your help on this. Very much appreciated. As I get more familiar with Delphi I am sure that my coding will improve.
  24. Columbo

    Help with Query at run time

    For some reason when I installed Delphi 11 Community the help files, documentation and example were not installed. Click on 'Help' or press 'F1' and nothing. As I mentioned, I looked around the internet and almost all of the examples were at design time.
  25. Columbo

    Help with Query at run time

    On my form I had TFDConnect (conPlife), FDTable (tblPlife) and Datasource1. I placed a TFDQuery component on my form. When I went to set the Connection property it was already pointing to my connection 'conPLife'. When I run the program it is not flagging any errors but it does not display any data in edtName when run. I thought maybe in the FDQuery1 properties I might have to set Active to True but when I did I got dialog saying: [FireDAC][Phys][SQLite]-306. Command[FDQuery1] text must not be empty. The Active was reset to False. Here is my entire code so far: unit Dinobase_u; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls, System.ImageList, Vcl.ImgList, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, Vcl.DBCtrls, Vcl.Buttons; type TfrmDino = class(TForm) pnlTitlebar: TPanel; Image1: TImage; pnlHeader: TPanel; Image2: TImage; lblName: TLabel; edtName: TEdit; lblMeaning: TLabel; lblPronounce: TLabel; edtPronounciation: TEdit; edtPeriod: TEdit; lblPeriod: TLabel; edtMeaning: TEdit; edtMainGroup: TEdit; lblMainGroup: TLabel; pnlFooter: TPanel; Footer: TImage; edtSize: TEdit; lblSize: TLabel; edtLived: TEdit; lblLived: TLabel; edtDiet: TEdit; lblDiet: TLabel; edtFossils: TEdit; lblFossils: TLabel; memFactfile: TMemo; PLTabSheet: TPageControl; TabSheet1: TTabSheet; SizeComp: TTabSheet; dinoImage: TImage; dinoSize: TImage; conPLife: TFDConnection; tblPLife: TFDTable; DBNavigator1: TDBNavigator; Datasource1: TDataSource; edtRecno: TEdit; lblRecno: TLabel; BitBtn1: TBitBtn; Query: TFDQuery; procedure FormCreate(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure getdbrecord; end; var frmDino: TfrmDino; implementation {$R *.dfm} procedure TfrmDino.BitBtn1Click(Sender: TObject); begin Application.Terminate; end; procedure TfrmDino.FormCreate(Sender: TObject); var img1: String; img2: String; begin WindowState := wsMaximized; lblName.Font.Color := TColor(#575); lblMeaning.Font.Color := TColor(#575); lblPronounce.Font.Color := TColor(#575); lblPeriod.Font.Color := TColor(#575); lblMainGroup.Font.Color := TColor(#575); lblSize.Font.Color := TColor(#575); lblLived.Font.Color := TColor(#575); lblDiet.Font.Color := TColor(#575); lblFossils.Font.Color := TColor(#575); edtName.Font.Color := TColor(#575); edtMeaning.Font.Color := TColor(#575); edtPronounciation.Font.Color := TColor(#575); edtPeriod.Font.Color := TColor(#575); edtMainGroup.Font.Color := TColor(#575); edtSize.Font.Color := TColor(#575); edtLived.Font.Color := TColor(#575); edtDiet.Font.Color := TColor(#575); edtFossils.Font.Color := TColor(#575); memFactfile.Font.Color := TColor(#575); lblRecno.Font.Color := TColor(#575); // Set image name img1 := 'Anomalocaris'; img2 := 'Anomalocaris_size'; //TImage.dinoImage.LoadFromFile(img1); //TImage.dinoSize.LoadFromFile(img2); end; //Add a procedure here to clear all TEdits, Memo and Pictures procedure TfrmDino.getdbrecord; //Get record procedure var sName: String; //holds name of dino record to retrieve begin FDQuery1.SQL.Text := 'SELECT name FROM dino Where name = :PName'; FDQuery1.ParamByName('PName').AsString := sName; FDQuery1.Open; //place data into edtName edtName.Text := FDQuery1.FieldByName('name').AsString; end; end.
×