How to get dataset to populate data into dbgrid in Delphi 6? - delphi

I have created a DBGrid in Delphi 6 and tied it to a DataSource contained in a DataModule. The Dataset for that source in also located in the same module. In the OnShow event for the form, I activate the dataset and set a label equal to the rowcount for the dataset. This shows several hundred rows but nothing shows in the dbgrid. If I activate the dataset in the IDE, the grid populates with the expected data. Does anyone have any idea why this behaviour would change between the IDE and normal runtime? We are also using SDAC connection components.
All 3rd party component choices are not mine to change.
I can elaborate as necessary for clarification, but I mainly need troubleshooting ideas to start at.

I have observed many times in D6 that the data controls can lose their settings at runtime, particularly the ones that associate one control with another. You might like to try setting the relevant names explicitly in your OnShow code before activating the data source.

I haven't been working with delphi for a few years, but I remember that the datasource property sometimes get lost if the dataset is kept active = true in design time.

Related

Delphi Livebindings, Grid shows (BCD)

trying to implement a query viewer in FMX Windows, which allows user to write a query and display its results.
the problem at hand is with fields of type Currency (or BCD, depending on the database), which is being rendered into the grid as "(BCD)" as shown below:
this question describes the exact same problem, specifically for FireDAC users. For the sake of trying, using FireDAC, the amounts in Currency fields are displaying correctly.
However, I am not using FireDAC. In fact, I am not using one specific set of DACs, as it varies with the underlying database in use.
I checked the options available in TBindSourceDB, the grid itself, but none would render the amounts correctly.
Any suggestions on solving this (other than converting the application to VCL and using a TDBGrid)?
Edit:
Delphi 10.3
DAC: TADSTable (Advantage), TEDBTable (ElevateDB) to name a few
MVCE: not much coding to share here, just drop 2 components, a TGrid and a data-access-component mentioned above (with a Currency field), link them up via visual livebindings and that's it.
came back to this problem after a few months, and managed to resolve it, so here's how it worked:
Removed the TGrid, and used a TStringGrid instead. Now the livebindings are able to render fields of type Currency without any extra manual configuration.

FireDac Polling records on demand and show them in StringGrid

I am using Delphi 10 Seattle, FireDac, Oracle Database and the TMS Components.
I am looking for a method that allows me to load data from my dataset/query and put it on a StringGrid on demand. I think the correct expression would be paging.
When i have a huge number of records (5000+) my application is freezing (~5s) till it loads all of them in the grid.
I've read the wiki post from Embarcadero about Fetching Rows but i didn't find a solution there.
I tried different combinations of the TFDQuery FetchOptions and ResourceOptions but without luck.
I noticed that the SQLDeveloper by Oracle performs exactly how i want my application to behave.
I've recorded this short clip to demonstrate how the SQLDeveloper loads massive amounds of records:
https://gfycat.com/BlankOrganicIndianpalmsquirrel
It first loads 50 records and as I scroll through the grid the other records get loaded.
So the question is how can i get the same polling technique like SQLDeveloper.
Thanks!
EDIT: Was using LiveBindings. Switched to db-aware components and it looks fast as lightning now.
As mentioned in the comments i gained a huge performance speed by switching from LiveBindings to the DB-aware component DBGrid.
For smooth scrolling i used this SO answer:
Delphi dbgrid continuous scrolling

How to switch to TBindSourceDB at runtime after design UI with TPrototypeBindSource?

I am trying the LiveBindings in XE3.
I have design a form with some controls using TPrototypeBindSource. The controls are bounds to fields in TPrototypeBindSource using visual designer. I can see the random data on the controls in design time and I am happy with the layout.
Next, I want to hook the UI controls to live data store in TClientDataSet instance. Is there an easy way to do it?
I try the TPrototypeBindSource.OnCreateAdapter event, but I couldn't find a suitable TBindsourceAdapter for TDataset. There is a TBindSourceDB but it is unable to hook to TBindSourceAdapter.
The only solution I found is I have to re-assign the link from TPrototypeBindSource to TBindSourceDB, by doing so will make the random data lost in design time.
Is there any way to make design time using prototype data and runtime using Dataset's data?

Delphi - How do i find out what a component is doing 'behind the scenes'

Im attempting to write a new component descendant from a common component (TDateTimePicker). My ultimate goal is to sub-class the TDateTimePicker so that when the user enters the component, the 'SelText' is set to a particular part of the DateTime.
At the moment, the behaviour of the TDateTimePicker is to focus the last selected text when it receives focus again. What i would like to acheive first, is to find out (look at) the code that actually is executed when the user focuses the TDateTimePicker.
I can see TDateTimePicker is a decendant of TCommonCalender which in turn is a decendant of TWinControl. But ive tried placing a breakpoint on procedures in TWinControl and they cannot be reached (which i guess is correct behaviour since a lot of components inherit from TWinControl).
So how do i find out what is happening when the user enters a TDateTimePicker? What code is run? Is it all hidden? I would hope this may shed some light on what i need to do to override the default bahaviour to accomplish my goal.
TDateTimePicker is a wrapper around a Windows Standard Control. The Delphi wrapper simply sends messages to the Windows control, so there's not much Delphi code to read.
You'll have to treat the TDateTimePicker as a "black box". Whatever happens in there, it's an implementation detail you're not supposed to care about. In fact the implementation details for the Date Time Picker have changed, for example, with Windows 7!
In Project|Options|Compiler check the 'Use debug DCUs' and the rebuild the application. Depending on the Delphi version this checkbox can be found in different places, this is for Delphi 2007.

Where should I begin when building a component?

I am looking to build my own component and have no idea where to begin. I have some Delphi books but they are old and outdated, and am looking for some recommendations on tutorials/books to help me do this. The component will be pretty simple, basically 2 labels and an image. I need hundreds of these in an array, so I thought a component would be the best route. The text will adjust based on width etc, and have some mouseover events. So basically, where do I begin?
I am using Delphi 2009, this will be a win32 app.
Thanks!
You can order Ray Konopka's book Dev. Custom Delphi 3 Components - PDF for 25$. It's a specialized book on the subject and very good for a beginner too.
The main principles behind developing components is:
Whether the component is visual or
not (Does it need a Canvas to paint on)
Does it need a window handle or not (visual or non-visual)
Once you answered those questions you can look at Delphi's source code for examples.
As far as I know, Delphi Component Design, by Danny Thorpe, is still the best book on the subject. Component design hasn't changed significantly in the last 15 years, so whatever books you have probably aren't as outdated as you think. There are three things to keep in mind while reading older references:
Names of certain units have changed. There's no DsgnIDE anymore, for example. It's DesignIDE instead.
Design-time code is strictly separated from run-time code now. This means you can't use DesignIDE in your component's unit, or else you're barred from using run-time packages. Older Delphi versions didn't have this technical restriction (although it's always been a legal restriction), so old code examples you find might need to change a little bit.
Strings are Unicode now, so as with all old code examples you find, there might be some invalid assumptions about character sizes that you'll need to recognize.
The biggest obstacle to writing components is that you're expected to use various protected members of the classes you descend from, but those frequently aren't documented, so you'll have to be much more willing to go read the VCL source code for examples of how various methods are used.
The easiest way to do what you want is to create a new form. Drop the labels and image and arrange them the way you want; if it suits your need, put them on a panel so they can be moved around as a unit.
Select all the components you want included (and including the panel if you chose to use one), and then click the Component item on the IDE's main menu, and select the "Create Component Template". (It's only enabled if you have selected components on the current form.) A dialog will appear asking you for a name for the new component, and the Component Palette page on which you want it to appear.
Take a look at this article, which describes how to build new components made up of a group of existing components.
Don't worry about your books being old.
Just about everything from the old days still works fine and what little doesn't is generally due to name conflicts or the addition of Unicode in the 2009 version.
They aren't Microsoft, they don't go breaking old code without good reason. In fact, take some code from the old DOS days--assuming it doesn't try to manipulate the screen it's likely to run with minimal fixup.
Don't worry about your old books! Since v3, Delphi hasn't changed much. This is why most of the programs compiled with D3 still compiles in D7 or even newer versions. And if it doesn't compile, probably you need to change a line or two, here and then.
I would recommend you to search other VERY simple components on Internet and see how they are made. Then make your own and post it here. Let other take a look at it and suggest improvements or spot bugs.
About your control's design:
1) maybe you DON'T need those two labels. You can just paint the text directly on the image. If you have lots of those components as you say, you may save a little bit of memory.
2) you may NOT want to have lots and lots and lots of images loading in one form. The overhead may be significant. What you can do is to load the pictures ONLY in images that are visible on screen - and you will put on screen ONLY 5-10 images (or whatever number of images you can show on the form without going out of screen). As the user scrolls down, you keep the same same TImage controls on screen but you load new (next) images in them.
3) You may not want to store labels and TImage in an array (I suppose it is an TImage because it seems you want to show them on the screen else you won't need labels - you need to explain your problem in more details if I got it wrong). But you can store a TBitmap and the text (that you want to display in labels) instead.
So, you may need to calculate how much CPU/disk overhead your hundreds of controls will create and how much memory they need. If you stay well under 1GB and the loading time is under 10 seconds, then it is relatively ok. IF not, you may want to think about your control's design before starting to actually implement it.
Hope this was helpful.
See ya.

Resources