Jump to content

Gary

Members
  • Content Count

    128
  • Joined

  • Last visited

Everything posted by Gary

  1. Gary

    Help with Query at run time

    Should work
  2. Gary

    Help with Query at run time

    @Columbo FWIW Listen to Remy! He's been around for a while, even part of the old Team 'B' I believe. He's one of the few experienced programmers that actually help newbies, and that takes patience. He helped me some time ago with some Interbase deployment issues that looking back were so simple yet at the time I just couldn't get it. Weirdo12 seems to be experienced with Database's especially Firebird, FireDac and Zeos so read his posts closely as well. I've learned a lot just reading them 🙂 The Database landscape has changed drastically since DBase and the Borland Database Engine. Everything is in the cloud, 3 Tier and Rest and it is good to embrace this change for Enterprise applications, but for the kind of Home and friend use that you and I do, Delphi offers much simpler 2 Tier or even direct access solutions. For example, you can use a DBEdit instead of a plain edit and connect it to the "Name" field in your Query and never have to worry about 'Loading data' into controls. There are several Data Aware controls that you just set their DataSource, or additionally a particular field and the data just display's. You can right click on the TFDQuery in your designed and if you have your connection active you can use the 'Parameters' tab to set a value and see the result at design time, and more.. Much of what you are doing looks like a console application. Everything is Visual now. Like Remy said set up your UI in the Object inspector, look for properties, there is a WindowState property set it in the designer to wsMaximized not in code (Check out the Position property of the form). In the last projects you posted what you are trying to do can be done in the designer and only 1 or 2 lines of actual code. While that may not sound exciting if you want to write code, you can whip out a simple Home use DB application that way in a matter of minutes, very exciting! BTW online help for Delphi 11 can be found here: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Main_Page
  3. Gary

    Help with Query at run time

    @Columbo Glad you did not give up! The control that is selected (Focused) when your app runs is determined by it's TabOrder. You can see this as a property in the Object Inspector. To reorder them you can change them manually or right click the edit box and select TabOrder... to arrange all components.
  4. Gary

    Help to find database error

    I would agree with Stano! However, this means you need to install 3rd party packages. You will need Data Access components. Zeos is popular. You will need to install and learn Firebird. Firebird and Interbase have the same roots. They were forked from same source some time ago. Embarcadero continues to develop it as commercial software, even if the community edition lets you build with IBLite, you will need to pay a license to use it outside the IDE. Firebird.org continues on the open source version. I believe they just released version 5? I did some projects with Firebird. They still work, but I personally find it difficult to work with. No doubt it is my lack of experience. I'm sure there is freeware that can at least export your old data to a .csv file, then as Stano said you can use FireDac BatchMove component to import into your Database of choice. I just added this feature to the one and only commercial app I have. It downloads GPS data in .csv format from the company's vehicle tracking service and imports it into a MYSQL Database.
  5. Gary

    Help to find database error

    What version of Delphi are you using? I have Pro + Devart Data Access components. Pro edition supports SQLite & Interbase Lite with Firedac out of the box, but not client/server (MySQL, Oracle..), not sure if the community edition supports any Databases. If you are using a trial edition Database support will end. If community edition supports SQLite I wouldn't discount it so fast, especially if you want to do any mobile apps. I'm trying to decide to use it or IBLite that comes with Pro on my next app since I want to support mobile. You can use Devart UniDac (commercial), or Zeos Database components (Open Source) for Database access with the community edition as long as your not making >5K annually from it. Both allow you to connect to many Databases. Firebird is a favorite of many Delphi developers, and has a client/server but also what is considered an embedded version. You just distribute a few files with your exe. This works well for small hobbyist apps. Firebird is actively supported. I used it in my last 2 small apps that will run from a USB drive. Another option is an older Database, "Advantage". SAP discontinued support a few years back at version 12, but the source is still available. It allowed you to use the local (embedded) version with up to 5 users before having to purchase the client/server version. It only works on Windows, but you just deploy 2 dll's minimum. The good thing with it is it has it's own data access components, just like the FD ones you just used. It has it's own GUI for creating and testing your databases. I just installed it on Delphi 12 and it still works just fine.
  6. Gary

    Help to find database error

    @JonRobertson That's great. I didn't see where he uploaded his database. Did you create it from his image?
  7. Gary

    Help to find database error

    @ColumboYour 2 hours ahead I'm in California You definitely need to figure out the SQL. If the tool you use doesn't let you test SQL statements, try DB Browser for SQLite (sqlitebrowser.org) Free/Donate. Now that you know it works with the table, you can try experimenting in the FDQuery editor. Right click FDQuery select Query Editor, enter your SQL and press Execute. The Delphi sample data retrieves the employees table with any of these 3 statements: SELECT * FROM employees SELECT * FROM 'employees' SELECT * FROM 'employees'; Can't help but think your table name being all uppercase is the problem. Try putting it in single quotes like above. I don't use SQLite so maybe someone else knows the problem for sure. Cool thing about Delphi is there is always "more than one way to skin a cat". In the Object Inspector for the Table set the Filter property to hyear = '1942', you only need the quotes around 1942 if it's a string, if the field is a number their are not needed, and the Filtered property to true.
  8. Gary

    Help to find database error

    Now use your original code to populate the memo, just use the Table
  9. Gary

    Help to find database error

    If the Active property is checked as true your good!!! You can try hooking up a DBGrid just to give yourself an extra boost. Drop a TDataSource on the form, set it's DataSet property to your table. Now a DBGrid and set it's DataSource property to the DataSource. If the Table is active you'll see the data
  10. Gary

    Help to find database error

    Some like to always use a Query, but if your just doing a SELECT *, a table component is way easier. You just set the connection and TableName properties, no need for a SQL Statement at all.
  11. Gary

    Help to find database error

    The tool in your previous post showing the table in the Database. Try the FDTable first
  12. Gary

    Help to find database error

    You can also try adding a FDTable instead of a FDQuery. Drop it on the form, make sure it's connection property is set to your connection, make sure the connection is set to connected. With the FDTable selected, In the object inspector look for the TableName property. There will be a dropdown listing all tables in the DataBase. Select your table, then set the FDTable Active property to true. If no errors you are connected
  13. Gary

    Help to find database error

    Problem in your SELECT statement. Did you enter it without any quotes ? Just SELECT * FROM DAT2 ? Can you get the same query to work in your Database tool?
  14. Gary

    Help to find database error

    Yahoo! So no problem connecting. Now on to the Query. Make sure the connection property of the FDQuery Component is set to your connection then right click and select Query editor, enter your SQL statement. See my previous image. Then click Execute. What happens?
  15. Gary

    Help to find database error

    What happens when you press "Test"?
  16. Gary

    Help to find database error

    BTW this is all in the designer you don't need to even run the program to get it working
  17. Gary

    Help to find database error

    Look at the image of the Object inspector, it is the first property. You connect to the database by setting the connection to "Connected True". Check or uncheck the box in the Object Inspector. Image's I posted are for the connection, look close, there is no SQL this is the connection, only properties having to do with the connection to your Database. Any SQL will be in the Query component. Right Click the FDQuery and select Query editor, see image. Enter your SQL statement. No quotes or semicolon SELECT * FROM DAT2. Press execute if good you will see your data below and the SQL for the component will be populated, if not your SQL Statement is the problem. Even though you can see the table in the Database it doesn't mean your SQL is valid. I once had a problem when migrating a MySQL server from Windows to a NAS drive. The default on the NAS did not allow capitols in table names and the whole program would not work because all my tables were a mix of lower and uppercase, SQL was now invalid. If the program you use to create/modify your SQLite database allows you to write queries do so. Make sure it works and then copy it into the FDQuery
  18. Gary

    Help to find database error

    When you look at the Object inspector there are 4 properties to set, see the image below. Line 4 DriverName has a dropdown list set it to SQLite Line 9 LoginPrompt if you do not have passwords set this to false and no login prompt will show Line 10 Name change to something better than default I like conMain or something more descriptive of your DB Expand the Params Property and the third line is the Database path. the ... will open a File Open dialog. Now set Line 1 Connected to true, if you get no errors and it stays checked your good. Even easier is Lajos suggestion, Right click FDConnection select Connection Editor, you can set all parameters except LoginPrompt there and it even has a Test button. This is the great thing about Delphi. The sample image attached I created in about 30 Seconds without a single line of code. I know you don't need the grid but it is a way to easily confirm that you have a valid DataSet. From your posts I suspect there are simple typo's and a mixture of trying to set properties in code and at design time. I think your SQL statement is the culprit, not the actual statement but how you are trying to set it in code, forget about that and just enter it in the FDQuery SQL property. If you want we can walk through setting up your Dataset like the sample and you can concentrate on your processing code.
  19. Gary

    Help to find database error

    Don't give up!! Start over with fresh project and break it into smaller parts: 1) Connect to Database 2) Open Query 3) Process your data I Created a small test app to complete the first 2 steps and test them in less than 1 Minute with the Demo data, you can too! 1) With a fresh project drop a FDConnection on the form. In Object inspector Set DriverName to SQLite. Set Name to conMain (Easier to type latter) Open Params look for Database, use ... to navigate to your Database. Now set Connected to true. If all is well it will connect. Set Connected to False Add a button to the form Set name to btnConnect and Caption to Connect. Double click button and add code: conMain.Connected := True; if conMain.Connected then begin ShowMessage('Connected'); // btnOpen.Enabled := True; end; Run and press Connect. If all is well you'll get the message. Step 1 Done Add a FDQuery to form Set Connection to conMain (Designer will probably already have done it for you) set Name to qryDat2 Enter your SQL statement into the SQL Object inspector Set Connection back to Connected <-Important Right click Query, you'll get a dialog box with your SQL in it. Press Execute. If all is well you'll see your data. Set Connected back to False. Add another Button Set enabled to false. Name to btnOpen, Caption to Open. Double click and add code: qryDat2.Open; if qryDat2.Active then begin ShowMessage('Query Active'); // btnProcess.Enabled := True; end; Uncomment btnOpen.Enabled := True; Run and try it!! Add third button Set Name btnProcess Enabled to False; Caption Process Double click button and add your processing code here Uncomment btnProcess.Enabled := True; You can delete each setting individually and try adding them in code 1 at a time to get a better understanding.
  20. Gary

    Help to find database error

    Very helpful to have the tutorial link. You can set everything up in the designer to make sure it works, then try doing it all in code. Set the Connection's Connected property to true, you will get errors if everything is not set up. You may be missing the connection's driver name, notice the drop down. Select SQLite or in code: FDConnection1.DriverName := 'SQLite'; Add the Query to the FDQuery1' SQL property in the editor and set it's Active property to true, you'll get errors if it's not setup right. The Database path is wrong, you are setting the Connection's "Database" Parameter which is a file path. So it's "Database=" then path. You can set it 2 ways: FDConnection1.Params.Add('Database=' + Your path here); FDConnetion1.Params.Database := Your Path here; You can use "ShowMessage" for a little logging. After setting the Database path: ShowMessage(FDConnection1.Params.Database); Test after opening the connection: if FDConnection1.Connected then ShowMessage('Connected'); After setting the SQL: ShowMessage(FDQuery1.SQL.Text);
  21. Gary

    Help to find database error

    I started with Lotus Approach and dBase files 🙂 Just wondering, you know while your project is great for learning Delphi you can do the same thing with components and hardly any code? That's what got me interested in Delphi in the beginning. Drop a TDBGrid and TDataSource on the form, connect the Grids DataSource property to the TDataSource, set the DataSource's DataSet property to your Query and when you open the Query it populates the Grid automatically including FielNames as headers.
  22. Gary

    Help to find database error

    Coding Boot Camp 2022 – Learn to Program (learndelphi.org) This was great for beginners. Delphi must be used in schools in South Africa, many of the sessions were from instructors there and referred often to this book: Dr Kevin R Bond on Delphi-Books.com
  23. Gary

    New proyect in Delfos

    FWIW I'm a hobbyist with 1 commercial app out there that is only on a LAN. I use Delphi Pro with Devart Unidac the standard edition is $299.00 Pro $499.00 they have a 15% sale good for 4 more days. I have a few personal and non-profit databases in the cloud, Dreamhost $13.99 mo. using 2 tier solutions (direct connection) with MySQL, and it's no more difficult than using a local database, just get the server address from the provider. It works fine. I do have to do most of the database management with their tools though. Like Carlos I keep hearing that it's all old school, and unsafe. REST is the way to go. While REST itself seems pretty straightforward with many tutorials on how to do it on a local computer, they all stop there. If you have no experience with web development it's the deployment that is the roadblock. I once asked about deploying REST to Dreamhost on a webinar and the response was "It can be done but was difficult with that provider". So what kind of provider service do you need? How do you connect the REST server to the database hosted in the cloud? Responses are usually like David's "I would suggest registering for a AWS account 12 months free tier and using Aurora PostgreSQL." (absolutely no offence intended). Looking at AWS's offerings will give you a headache, and what is "Aurora"? Another layer? It would be great if there were a tutorial out there with a real-world example of setting this up on a real host. I purchased TMS All Access. It comes with components to create a REST server and more. Also their class and Holger's books and am looking forward to some time to dig into it, but in skimming the info It wasn't obvious it will cover that. Still I'm hopeful.
  24. Gary

    Help to find database error

    Yes! What Remy said! Your form is your class and defined in the interface section of the file. This is just the description or declaration of the class, you write the code later in the implementation section type TfrmDatabaseTutorial = class(TForm) //<- Class name btnConnect: TButton; btnExecute: TButton; SQLConnection1: TSQLConnection; memOutput: TMemo; SQLQuery1: TSQLQuery; procedure btnConnectClick(Sender: TObject); //<- procedures of your class no need for TfrmDatabaseTutorial procedure btnExecuteClick(Sender: TObject); //<- procedures of your class no need for TfrmDatabaseTutorial private { Private declarations } public { Public declarations } procedure ShowSelectedResults;//<- procedures of your class no need for TfrmDatabaseTutorial end; // <- Definition of your class ends here When you write your code the unit needs to know what class your procedure belongs to since you can have multiple classes, so you need it here: implementation TDatabaseTutorial needs to be here so compiler knows what class the procedure belongs to. Multiple classes can have the same procedure names and often do so you have to distinguish them. procedure TDatabaseTutorial.ShowSelectResults; begin //code end;
  25. Gary

    Help to find database error

    look at the event handlers Delphi created btnConnectClick(Sender: TObject) and btnExecuteClick(Sender: TObject) to see this. You can use ctrl + shift + up or down arrow to toggle between interface and implementation sections. Also it doesn't hurt but the () are not needed if you have no parameters.
×