Squall_FF8 1 Posted 14 hours ago (edited) Hey guys, I have a table in MS SQL that holds in one column the file names of existing files in a local storage. When I show this table with TFDQuerry, I would like to add visually extra info - the file size. So what I did is to add extra calculated field Size. OnAfterOpen I get the file sizes in a Dictionary<ID, FileSize>, and OnCalcFields I simply fetch the file size from the Dictionary. The problem is - OnCalcFields is called before OnAfterOpen, actually the order by debugging is: Calc, AfterOpen, Calc. The result on screen is - some rows have Size 0 (no value in the Dictionary). After a scroll in the display Grid, all works fine. Could you help me resolve this? Or if you have a better way for a task like this? Edited 14 hours ago by Squall_FF8 Share this post Link to post
Uwe Raabe 2146 Posted 14 hours ago I would use a caching approach. In OnCalcFields try finding the ID in the dictionary like you already do. If not found, get the file size as you currently do in OnAfterOpen and add it to the dictionary. 1 Share this post Link to post
Squall_FF8 1 Posted 13 hours ago 10 minutes ago, Uwe Raabe said: If not found, get the file size as you currently do in OnAfterOpen and add it to the dictionary. Thank you! So kind of FetchOnDemand approach, I like that. It will be even less code P.S. Does anybody knows why we have such weird execution order: Calc, AfterOpen, Calc? Is there anyway to control this? Or at least to "force" Grid to display the fetched values in the second Calc? Share this post Link to post
Uwe Raabe 2146 Posted 13 hours ago 16 minutes ago, Squall_FF8 said: Does anybody knows why we have such weird execution order: Calc, AfterOpen, Calc? Calculating fields is done on each record at several occasions. Any change to the current record, be it by navigating or switch to and from edit mode. AfterOpen is dataset based and when it is called, at least the first record is already loaded and all fields contain their values, including the calculated ones. 1 Share this post Link to post
Die Holländer 84 Posted 13 hours ago Just for interest.. >>Dictionary<ID, FileSize> How did you fill this Dictionary and why are you using it during the OnCalcFields and not using the extra calculated field from the resultset itself for displaying? Share this post Link to post
Squall_FF8 1 Posted 7 hours ago 5 hours ago, Die Holländer said: How did you fill this Dictionary if not Dic.TryGetValue(QryID.AsInteger, n) then begin var info: TWin32FileAttributeData; GetFileAttributesEx(PChar(QryFileНаме.AsString)), GetFileExInfoStandard, @info); Dic.Add(QryID.AsInteger, info.nFileSizeLow); end; GetFileSize is probably faster, but require more code. Also the result is limited to 4GB. If you need larger sizes you need to account for nFileSizeHigh too. Share this post Link to post