-
Content Count
2982 -
Joined
-
Last visited
-
Days Won
134
Everything posted by Remy Lebeau
-
Why are you creating an HDC to begin with? TBitmap already has its own HDC that it manages for you. Just draw on your TBitmap whenever you need to. What are you trying to accomplish exactly by managing your own HDC manually? You don't need that 2nd step. You can't. Resizing a bitmap will destroy its old data. But TBitmap will handle copying the old data into the new memory for you. You would have had to do that yourself with a manual HDC, so better to just let TBitmap do it for you.
-
Simply set the TPageControl's ActivePage property back to Tab1, eg: procedure TfrmDino.getdbrecord; var ... begin ... PLTabSheet.ActivePage := TabSheet1; end;
-
OK, first problem... what do you see in the following snippet? (ignoring the unused img variables here) You are calling getdbrecord() in the Form's OnCreate event! What value does edtSearch hold when the Form is first created, BEFORE the user has a chance to type anything into it? Is it blank? Does it have a default value? We don't know, but I'm guessing it is not a valid record name. OK, next problem... see anything wrong with the following snippet? The sName variable is BLANK when you use its value to assign the img1 and img2 variables! Not that it really matters here, since you are not actually using those img variables for anything useful to begin with, but it is still something to be aware of so you don't make this same mistake again in the future. Lastly, just on a side note, in the following code snippet... You should be checking that TFDQuery.Open() actually found a matching record before you access the Field values. If TFDQuery.Open() does not find a match, the TFDQuery.Bof and TFDQuery.Eof properties will both be true, eg: ... FDQuery1.SQL.Text := '...'; ... FDQuery1.Open; if FDQuery1.Bof and FDQuery1.Eof then begin // no matching record found, do something... end else begin // place field data into tedit controls... end; Now, let's put all of that together... procedure TfrmDino.BitBtn1Click(Sender: TObject); begin Close; end; procedure TfrmDino.btnSearchClick(Sender: TObject); begin getdbrecord; end; procedure TfrmDino.FormCreate(Sender: TObject); begin WindowState := wsMaximized; //getdbrecord; end; procedure TfrmDino.getdbrecord; var sName: String; imgPath: String; img1: String; //img2: String; begin 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; if FDQuery1.Bof and FDQuery1.Eof then begin ShowMessage('Name not found'); Exit; end; //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 imgPath := 'D:\Delphi_11_Community\MyProjects\Dinobase\dino_images\'; img1 := sName + '.jpg'; //img2 := sName + '_size.jpg'; dinoImage.Picture.LoadFromFile(imgPath + img1); //edtSearch.Clear; end;
-
The only LoadFromFile() code you have shown us so far is in the form's OnCreate event before the SQL query is performed. Please show your updated code that calls it after the SQL query is performed. That is just a copy/paste of the example code I gave you originally. What does your REAL code look like? Did you put a breakpoint on imagePath, or show it in a ShowMessage(), or anything to verify it is holding the correct path before you then pass it to LoadFromFile()? No, it doesn't.
-
'group' is a reserved keyword in SQL. To use a reserved keyword in an object name, like a column field, you have to surround the name with square brackets, eg: FDQuery1.SQL.Text := 'SELECT record,name,meaning,pronounce,[group],period,size,lived,diet,factfile FROM dino Where name = :PName';
-
Delphi 12 IDE, auto-formatter mutilates generics
Remy Lebeau replied to A.M. Hoornweg's topic in Delphi IDE and APIs
Please don't spread fake news. There is no such version. It is explicitly mentioned, in a roundabout way: Modeling is deprecated, and the current code formatter depends on it, so the formatter is also deprecated. -
It is raw RGB, use whatever values you want for the R, G, B channels. The code you showed is not using a dark brown, it's more like a red-ish brown. RGB(80,47,15) is actually #502F0F in paint programs (not to be confused with the '#xxxx' character constant notation in Pascal!). It is not. Completely different RGBs. TColor(#575) is decimal 575 is hex $23F (use any calculator to verify that), and TColor($0000023F) is R=63($3F) G=2($02) B=0($00). RGB(80,47,15) would be TColor($0F2F50). If you want to set that in code, you can use the actual RGB() function: edtLived.Font.Color := TColor(RGB(80,47,15)); BTW, you may want to have a look at the TControl.ParentFont property. Instead of setting the Font.Color on every control individually, you can set it once on their parent instead, and then have the controls inherit it via ParentFont.
-
Yes. You can enter a custom color value directly into the property editor, you just have to use decimal notation (drop the #) or hex notation, ie use '575' or '$23F' (without the quotes). Even in your code, don't use '#' for color values. '#' is used to specify a Char constant, and a character is not a color. Use TColor(575) or TColor($23F) in code, or more expressive TColor(RGB(63, 2, 0)) or TColor(RGB($3F, $2, $0)). It is highlighted because that TEdit has the input focus at the time. Simply put the focus somewhere else, such as the Form itself. Also, make sure the Form's ActiveControl property is not set at design-time (or, set it to the UI control you actually want to have the focus initially).
-
Where are you calling TfrmDino.getdbrecord() from? It is not in the code you have shown. You can't activate the query before you have configured it. Sounds like you hadn't defined the SQL for it yet before trying to use it. All of that setup stuff you are doing in the Form's OnCreate event should be done using the Object Inspector at design-time instead. Start with this: https://docwiki.embarcadero.com/RADStudio/en/FireDAC
-
Obviously, you need to adjust the code for your particular setup, which you did not provide ANY details about, so I could only give you a GENERAL solution. What kind of database are you are trying to access? What component(s) are you are using to access that database? My example was meant to represent whatever Query component you are actually using on your Form, such as a TQuery, TFDQuery, etc. Use whatever the actual component name really is. Not a String variable. Have you read Delphi's documentation on working with Databases? There are whole books on this subject.
-
Yes, I see the same issue happen, the top of the Recent menu is WAY off screen:
-
There should be no difference between setting up a query at design-time vs runtime. So, what are you REALLY having trouble with, exactly? Can you show the actual code that you are having trouble with? All you need is something like this: Query.SQL.Text := 'SELECT Name, OtherFieldsAsNeeded from dino where Name = :PName'; Query.ParamByName('PName').AsString := sName; Query.Open; edtName.Text := Query.FieldByName('Name').AsString;
-
No, I was actually referring to the compiler's Library and Browsing Paths, the debugger's Source Path, etc. There are multiple search paths in a project, make sure none of them are referring to Indy's source folder during compiling. You don't want the compiler finding Indy's source code if you want to use the pre-installed version. You said you re-installed the IDE and transferred over old projects. Do you have the same problem if you start a new project fresh? What IDE version were the old projects written in? It is generally a good idea to create a new project in the new IDE and then add your existing source files to the new project as needed, rather than just open an old project in the new IDE.
-
Is there more to the error message? I would think it would tell you WHY it can't compile the unit. In any case, it sounds like the project is trying to recompile Indy from its source code. Does the project refer to Indy's source code folder directly? It shouldn't, so if it does then remove that folder from the project's search directories. The project should only be using the pre-installed unit/package binaries that were already compiled for the IDE.
-
Assigning custom colors to properties via code at runtime is trivial, as shown earlier. But if you want to choose custom colors at design-time, that is possible but not trivial, as you have to write your own custom property editor and register it for TColor, overriding the default property editor. See webcolors and custom colors in Delphi's Object Inspector colorpicker at design-time Custom colors in Delphi 7
-
Profile - currently no entry Delphi 12
Remy Lebeau replied to Brian Evans's topic in Community Management
There is now. -
It has been added. Oddly, it is listed as just "Delphi 12" instead of as "Delphi 12 Athens".
-
Delphi 12: Install Packages inconsistency?
Remy Lebeau replied to PeterPanettone's topic in Delphi IDE and APIs
Sure, but I shouldn't really have to go to that much trouble in the first place just to get basic behavior. -
And RandomFrom()
-
RandomRange() has been around since Delphi 6.
-
Can you be a little more specific? What are the full error messages? Are you trying to use the version of Indy that ships preinstalled with the IDE (it should "just work" out of the box), or did you replace it with a newer version of Indy?
-
One option would be to create 4 lists and fill them with the possible numbers, and then generate a random index for each list, where you remove each found number from subsequent lists before generating indexes for them. For example: var values1, values2, values3, values4: TList<Integer>; value1, value2, value3, value4, index: Integer; procedure populate(list: TList<Integer>; startValue, endValue: Integer); var value: Integer; begin list.Capacity := endValue - startValue + 1; for value := startValue to endValue do list.Add(value); end; procedure checkAndRemove(list: TList<Integer>; startValue, endValue, valueToRemove: Integer); begin if (valueToRemove >= startValue) and (valueToRemove <= endValue) then list.Remove(valueToRemove); end; begin values1 := TList<Integer>.Create; values2 := TList<Integer>.Create; values3 := TList<Integer>.Create; values4 := TList<Integer>.Create; populate(values1, 1, 300); populate(values2, 100, 550); populate(values3, 250, 750); populate(values4, 500, 1000); index := random(values1.Count); value1 := values1[index]; checkAndRemove(values2, 100, 550, value1); checkAndRemove(values3, 250, 750, value1); checkAndRemove(values4, 500, 1000, value1); index := random(values2.Count); value2 := values2[index]; checkAndRemove(values3, 250, 750, value2); checkAndRemove(values4, 500, 1000, value2); index := random(values3.Count); value3 := values3[index]; checkAndRemove(values4, 500, 1000, value3); index := random(values4.Count); value4 := values4[index]; values1.Free; values2.Free; values3.Free; values4.Free; end;
-
How to remove C++ from RadStudio 12 after installation?
Remy Lebeau replied to Bart Kindt's topic in VCL
Perhaps run $(BDS)\bin\LicenseManager.exe and remove your beta license if it's still listed? -
Delphi 12: Install Packages inconsistency?
Remy Lebeau replied to PeterPanettone's topic in Delphi IDE and APIs
Agreed! Something that is really annoying me since installing 12.0 is when I double-click on a .pas/.cpp file outside of the IDE, and the IDE is not running yet, the IDE is started, but it wastes time loading all of its default packages and layouts, and then opens the .pas/.cpp file, and then finally goes to the Welcome screen instead of the .pas/.cpp file. Loading the packages, the Structure view, the Palette, etc is all completely unnecessary and the Welcome screen is completely unwelcomed when I just want to view a file. I expect the IDE to basically just present me with the code editor and nothing else. If I want the full IDE experience, I'll open the full IDE myself, or at least open/create a project and expect the IDE to (re)load everything it needs to support that task. -
Better to use CompilerVersion (and RTLVersion) instead, then you don't need to update the defines every time a new version is released, only when you need to add a new define, eg: {$IF DEFINED(DCC) OR (CompilerVersion < 23)} {$DEFINE EC_DELPHI} {$IFEND} {$IF CompilerVersion >= 20} // Delphi 2009 {$DEFINE EC_UNICODE} {$IFEND} {$IF CompilerVersion >= 34} // Delphi 10.4 {$IF CompilerVersion < 35} {$DEFINE EC_VCL27} {$IFEND} {$DEFINE EC_VCL27_UP} {$IFEND} {$IF CompilerVersion >= 36} // Delphi 12 ... {$IFEND}