

Squall_FF8
Members-
Content Count
63 -
Joined
-
Last visited
Everything posted by Squall_FF8
-
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?
-
That is a common misconception among developers and clients. The reason is - contemporary computers are way to fast to objectively judge what is slow and what is fast. Usually developers have fast computers with fast disks/memories. But what happens when you deploy to clients? (files are on the VPN network in my case). I would suggest to put a counter in your CalcField - to simply counts how many times your disk code was used. Then use your app as normal, especially scrolling records/view of the table. And check the counter, right before you destroy the form. You might get a surprise. But whatever number you get, its always a comparison of 1 to many (1 for cashed).
-
Hey Guys, I use a stock TDBGrid (Delphi 12.2) connected to an FDQuerry (MS SQL). One of the field is Hour (time7) and I would like to customize the output to just "hh:mm". Could you advise how that could be achieved?
-
Whoah that is exactly my case! Thanks to the help of the guys here, I also came to: "ODBC driver does not recognize these types and maps them to WideStrings" Unfortunately I dont know how to map, (or is it even possible to change it). As an easy fix, I just manipulate the string on GetText, it turned out the first 5 chars is what I need.
-
I dont understand your question .... If you read carefully my initial post, you will see that I use both. As @Uwe Raabe explained well, the Dictionary simply play the role of a cache, specifically - a disk-cache. In Fact the actual FileSize reading is done just once per file/record (on-demand).
-
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.
-
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?
-
Hey guys, I have a very weird situation: type tModel = record Field: string; Control: TWinControl; Kind: integer; end; tModels = class private FList: TList<tModel>; public procedure DoSomething; ... end; procedure tModels.DoSomething; begin FList[1].Field := 'somthing'; end; When I try to compile I get error: [dcc32 Error] E2064 Left side cannot be assigned to Why I get this error? That would mean I cant have direct access to the fields of the record for manipulation ... P.S. FList[1] := Value; where Value is tModel works.
-
Thank you! Typing things like Models.List.Field defy my goal to access an object as array: Models.Field, but at least works Later on if I have time I might experiment to change the TList with dynamic array
-
Hey Guys, I have TImage that in run-time I can load with png or jpg. 1. How to check is the TImage empty (aka no image loaded? 2. How to erase the loaded image? (when an image is loaded)
-
Thank you @Remy Lebeau! BTW do you know, why Image1.Picture.Bitmap.Empty clears the image? It is suppose the return a value, not to destroy an image
-
Solid advice! Since I'm stubborn when I feel I'm so close, I decided to test all types (that make sense) - time, time 0..7 and datetime variants. From the 14 possibilities, only 2 gave me (The rest was tWideString): QryHour: TSQLTimeStampField; Browsing MS SQL types page I stubbled upon: So maybe it is ok to get WideStringField. On the other hand, Date formats return SQLTimeStamp ...
-
Update: Sorry guys for the delay but we had a break (National holidays). So I thought that the problem comes from my weird setup: Delphi 12.2, 64 bit application, no design time info for TFDConnection, no SQL for TFDQuerry, all done in run-time. After @Uwe Raabe showed me tTimeField, I decided to play by the book: a new 32 bit app, (because Delphi IDE is 32) design time connection + query (with SQL) , Auto-created fields in design time. All of the fields got appropriate type (Int, Date got TSQLTimeStamp, Currency,..) except the Hour field: QryHour: TWideStringField; If it matters, the MS SQL is old 2008. I also tried to cheat with static field, but the result was the same (error message after opening the query) This leads me to the conclusion: Delphi 12.2 has a bug for MS SQL 2008 when the type is time(7). Unfortunately I cant change the type (easily) to experiment with other time versions or even try DateTime for Time portion. P.S. @Uwe Raabe, I tried your suggestions for mixing static dynamic fields - no result. Sorry but I have to ask - what version is your Delphi and are you using time(7) in MS SQL?
-
Name=Jet DriverID=MSSQL Server=192.168.0.169 Database=xxx User_Name=xxx Password=xxx FDConnection is all default - (after you drop it on the form)
-
The screenshot shows that this is in Design time. Could you try that at runtime? The connection need to be closed on start, and activated with a button. Also the query to have at least 2 fields (Hour and whatever) (so we have a static and dynamic fields at the same time).
-
BTW I'm not sure is it related, but the Query and the Fields are dynamic. The columns are static. I did this because I needed custom labels for titles Here is the CD_Main ... As you can see I have plenty of types, yet they all come as WideString (after Open) CREATE TABLE [dbo].[CD_Main] ( [ID] INT IDENTITY (1, 1) NOT NULL, [ForWho] NVARCHAR (100) NULL, [Dates] DATETIME NULL, [Category] INT NULL, [Sum] MONEY NULL, [Notes] NVARCHAR (200) NULL, [Hour] TIME (7) NULL, ... CONSTRAINT [PK_CD_Main] PRIMARY KEY CLUSTERED ([ID] ASC) );
-
sure I can .... but I doubt there is a hint (for a problem) in it: Hour is a field of CD_Main. Personally I think the problem is from FD engine ... it returns all fields as WideString instead of appropriate type. const sql_Base = 'SELECT '+ ' m.*, cat.Name Categories, t.Name City,'+ ' c.Name FirmName, c.EIK FirmEIK, c.Address FirmAddress, '+ ' c2.Name ToFirmName '+ 'FROM CD_Main m '+ ' left join CD_Category cat on (cat.ID = m.Category) '+ ' left join CD_Town t on (t.ID = m.Town) '+ ' left join CD_Company c on (c.ID = m.Firma) '+ ' left join CD_Company c2 on (c2.ID = m.ToFirm)';
-
Hehe easier to say then do 🙂 Any hints? Why all fields are WideString? BTW that is tFDQuerry connected to tFDConnection.
-
I tried (long ago)... for unknown reason the quarry returns WideString instead of Time. And I dont know how to force the right type ...
-
Judging by the explanation, I would suggest that your design (using what component for what) is wrong! 1st Method: you want to use two thumbs on one track. The values that each thumb represent are the values that track represent. So first is Position - that is fine. But second is Length - it has nothing to do with the track (which represent position in the text). Your picture would make sense if the two thumbs are Start/End position. 2ndMethod. Using TrackBar in general is inaccurate - most likely you cant get with the thumb, all values that you need. The larger is the set that you want to represent, the higher probability is. The reason for that is the rounding error between thumb position on screen and resulting set. If the set has more elements then the length of the bar (in pixels) you will have 100% inaccuracy. SpinEdit on other hand is 100% accurate - with keyboard or mouse you can get all values that you need. So I would suggest to use 2nd Method with changing controls - use SpinEdit for Position in text (since text could be HUGE) and Trackbar for Length. P.S. I'm not sure about latest iterations of Delphi (10+) but in the past RxSpinEdit had some nice tricks with mouse (compared to stock SpinEdit).
- 7 replies
-
- delphi xe7
- trackbar
-
(and 1 more)
Tagged with:
-
Hey guys, I have a tDBGrid that I try to paint the selected row similar to the picture bellow. May you advise/share a snippet of how to do it? dgRowSelect is false!
-
Thank you very much for the solid advice! For completeness and people with the same problem, the solution is is simple: type TDBHackGrid = class(TDBGrid) public property Col; property Row; end; Then in your app you just compare: if Row = HackGrid.DataSource.RecNo then // code for coloring the row
-
Woah, you saved the day!!! I tried it and it works! That trick actually doesn't require to make a new class, install components, do hacky things!. It is enough in your app to write a handler for OnDrawColumnCell !!! Event the handler is almost the same: if not (gdSelected in State) and Grid.SelectedRows.CurrentRowSelected then Grid.Canvas.Brush.Color := TColor($FFFFA0)
-
That part is quite hacky ... When I change in the form and try to go back to pas, I get error in the IDE. The project compiles and works well, but I need to save first, close the project and then open it again
-
Only in the .pas. I cant find in Delhi12 how to view the .dfm as text EDIT: found it and it works, Thanks!!!