TGauge doesn't change value in runtime - delphi-7

At first, please bear with me, as I am quite new to the Delphi world. I am a former C++, C# and embedded developer.
I have Delphi 7 and Delphi RAD Studio 10.2 Starter on Windows 7 64-bit.
I have tried the TGauge component in both versions, as it is standard in Delphi (I think).
So, the issue is when I try to set the Progress property with a value at run-time, it doesn't reflect that on the GUI. But, if I set a value at design-time from the Object Inspector, it reflects the value as it should be, and the Gauge
paints the percentage correctly.
Steps to test this behavior:
Dragged and dropped the TGauge component from the "Samples" palette onto the Form.
I set MaxValue = 100 and MinValue = 0 in the Object Inspector.
I created a textbox (txtValue) on the Form.
I created a button (btnSetValueClick) on the Form and used this code:
procedure TMainForm.btnSetValueClick(Sender: TObject);
begin
Gauge1.Progress := StrToInt(txtValue.Text);
end;
So, I was expecting the Gauge would show the value entered, but it didn't.
When I debug the code, it hits btnSetValueClick() and sets the value inside.
What am I missing here?
EDIT: (This is the code in the form.)
object Gauge1: TGauge
Left = 53
Top = 81
Width = 191
Height = 113
ParentCustomHint = False
Color = clMenu
ForeColor = clRed
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'Default'
Font.Style = []
Kind = gkNeedle
ParentColor = False
ParentFont = False
Progress = 35
EDIT:
I have created a new project and started from scratch. I put the TGauge without changing any single properties of it. And it has started to work although I don't still see the difference can cause this behavior. At least this might give a clue this component can go wrong without an obvious reason, especially to beginners like me.
Please consider the case is as closed. Thank you.

Related

Windows Forms c++ cannot set default values in datagrid cells

I've just started working with Windows Forms on Visual Studio 2019. I am most familiar with C++ and thus have been creating an application with C++/CLI. The basis of the project is that I have a schedule generating set of functions these are called in MyForm.h which is the main form originally launched. MyForm.h also opens MyForm2.h when a button is pressed. This MyForm2.h is where I have a problem. I want to allow the user to edit a series of specific settings for the schedule generator. The most user friendly way I've found to do this is with a datagrid using textboxes and checkmarks, but I need to have the original timeslots for the schedule in the datagrid for the user to edit when the open MyForm2.h.
I've looked all over to find how to set default values for a datagrid, but have only come up with two ok methods, both of which have some fatal flaws.
The first was from this microsoft guide.
The problem here is that the solution is written in c#, and I don't know how to implement it in a c++ program.
The second was from a few sites which generally displayed one of two formats which are displayed here in a way that is formatted to how I used them in my forms:
void InitializeComponent()
{
this->dgvStudents = (gcnew System::Windows::Forms::DataGridView());
this->dataGridViewTextBoxColumn1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgvStudents))->BeginInit();
this->SuspendLayout();
this->dgvStudents->Columns->Add(this->dataGridViewTextBoxColumn1);
this->dgvStudents->Location = System::Drawing::Point(0, 0);
this->dgvStudents->Name = L"dgvStudents";
this->dgvStudents->Size = System::Drawing::Size(350, 100);
this->dgvStudents->TabIndex = 0;
//
// dataGridViewTextBoxColumn1
//
this->dataGridViewTextBoxColumn1->HeaderText = L"First Name";
this->dataGridViewTextBoxColumn1->Name = L"dataGridViewTextBoxColumn1";
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(638, 261);
this->Controls->Add(this->dgvStudents);
this->Name = L"MyForm3";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Exercise";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dgvStudents))->EndInit();
this->ResumeLayout(false);
// Option 1
this->dgvStudents->Rows[0]->Cells[0]->Value = "MLP";
// Option 2
this->dgvStudents->Rows->Add("MLP");
}
I have tried putting both options in several various parts of the InitializeComponent() function and it makes no difference. The problem with Option 2 of this second solution is that it will be removed from the code if I change anything in the [Design] part of the MyForm2.h code editor in VS and save it. Weirdly, Option 1 will not be displayed in the [Design] part of the code and instead I will get the error Member Cells not found in class System.Windows.Forms.DataGridViewRowCollection, but if I launch the debugger for the program, both options will be displayed exactly how I want them to be in the GUIs that appear. As previously meantioned though, both options will most likely be removed if I change anything else in the form designer. Any help would be greatly appreciated:)

Inconsistency with control location and control appearance

I have my "about" form looking like this on my computer (Win7 32 bits) and in the IDE
And on at least one PC (under Win7 64 bits), it looks like that :
2 questions about this :
Why is my OK button not appearing when there is nothing to hide it in my code? How can I solve that? The OK button appears when I click the other button or when I click on its location.
Why are my buttons and my labels shifted to the right, going out of the form I designed in VB6? There is nothin in my code to change their position.
A bit of information :
My buttons are inside a "Frame" control. This frame control is supposed to be 840 twips (VB6 unit...Why couldn't they use pixel?!) from the left and 525 from top. My labels are not inside anything.
Thank you.
Edit : the only code managing the windows is in the form_load. FraAbout is containing the buttons you see above, FraSplash contains a progressbar. The ZOrder make buttons always appear on top.
Private Sub Form_Load()
On Error Resume Next
Timer1.Enabled = False
LblRevision = App.FileDescription
SendMessage pb1.Hwnd, PBM_SETBARCOLOR, 0, ByVal RGB(114, 191, 68)
FraAbout.Visible = False: FraSplash.Visible = False
Me.ForeColor = 0: Me.DrawStyle = 0: Me.BorderStyle = vbFixedSingle: Me.Refresh
If AppLoaded Then
FraAbout.Visible = True
Else
t = 0: pb1.value = pb1.min: FraSplash.Visible = True: Timer1.Enabled = True
End If
End Sub
This all came from... my configuration panel. Here is how to fix the problem if you have it. I was at 125, just put it back to 100 :

Form property automatically changing on saving changes in VB6 (configured with VSS 2005)

I am facing below issue in VB6 :
When I checkout file file and check "Show differences" it is showing no difference (identical files) but when I save my changes without changing and form property and again check for differences in VSS , it is showing difference in few property.One of them is mentioned below.Kindly suggest.
Begin VB.Label CommStatus
BackColor = &H80000014&
BorderStyle = 1 'Fixed Single
BeginProperty Font
**Name = "Arial"** 'this property is changing
Size = 8.25
Charset = 204
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 375
Left = 240
TabIndex = 3
ToolTipText = "The most recently detected error"
Top = 360
Width = 7815
End
You can check attach image
After looking in to this, the reason for seems to be Windows zoom setting (100%,125% and 150%, control panel/Make text and other items larger or smaller). If the form is checked in to TFS/VSS/GIT in one zoom setting, and later edited in another, VB6 will change all kind of form properties to adjust for this. So this probably only happens in dev teams with 2+ users that happens to have different screen sizes and therefor different zoom settings.
Only way to avoid this is probably to all use the same zoom setting...

Shell_NotifyIcon NIF_INFO not showing icons

Im having issues with balloons firstly they refused to show at all but having found this thread:
Why aren't Shell_NotifyIcon balloon tips working?
then changing cbSize to 504 the balloons show but without icons in them, all the standard icons won't show nor will a custom icon, structure looks like this:
cbSize = 504
hWnd = HDL
uID = 10
uFlags = NIF_INFO
szInfo = sBody
uTimeout = 20000
szInfoTitle = sTitle
dwInfoFlags = NIIF_ERROR
does anyone know of a reason why the icons will fail? (Have tried all the structure sizes and uVersion in the various combinations)
Edit:
S.cbSize = 504;
S.hWnd = HDL;
S.uID = 101;
S.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
S.uCallbackMessage = 0x4DE;
S.hIcon = iHDL;
S.szTip = sTooltip;
S.uVersion = 3;
S.dwInfoFlags = NIIF_NONE;
Shell32.Shell_NotifyIconA(NIM_ADD,S:GetPointer())
Shell32.Shell_NotifyIconA(NIM_SETVERSION,S:GetPointer())
That's used to create the tray icon and it does:
All the callback messages work with the change tooltip/change icon/set focus/delete tray icon functions also working as expected on XP and Win 8.1 all using cbSize = 504 and uVersion = 3 with Ansi NIM_SETVERSION and NOTIFYICONDATA, balloons will show its just no icons will show not even the default ones:
S.cbSize = 504;
S.hWnd = HDL
S.uID = 101
S.uFlags = NIF_INFO
S.szInfo = sBody
S.uTimeout = 20000
S.szInfoTitle = sTitle
S.dwInfoFlags = NIIF_ERROR
Shell32.Shell_NotifyIconA(NIM_MODIFY,S:GetPointer())
Using size of structure for cbSize works for everything but balloons, they wont even show, and that size reports as 688.
cbSize=504 is only meaningful if you are using the Ansi versions of Shell_NotifyIcon() and NOTIFYICONDATA, are using the XP (v3) version of NOTIFYICONDATA, and your compiler's alignment settings are actually aligning the NOTIFYICONDATA fields correctly so the XP fields line up to exactly 504 bytes. Without seeing your actual code, your compiler settings, or any context information at all, there is no way to troubleshoot your problem further.

DataGridView problem when adding columns

Hey guys! First time I use Visual Studio 2008 Windows Form Application with C++.
I want to put a dataGridView on my form. That is ok. But when adding one column, on the gridView appear 2 columns. First with no header (which I dont want) and the second is ok(my column). I tried to set the column number from code, but the same thing happens.
Any idea to solve this?
Thanks,
Andrew
//
// table
//
this->table->AllowUserToAddRows = false;
this->table->AllowUserToDeleteRows = false;
this->table->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->table->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^ >(1) {this->Column1});
this->table->Location = System::Drawing::Point(13, 89);
this->table->Name = L"table";
this->table->ReadOnly = true;
this->table->Size = System::Drawing::Size(240, 150);
this->table->TabIndex = 2;
//
// Column1
//
this->Column1->HeaderText = L"Column1";
this->Column1->Name = L"Column1";
this->Column1->ReadOnly = true;
Are you adding the column in the constructor?
I've had a problem in the past where items added in the constructor get added twice, because (I think) the constructor gets called to make the control appear in the designer view, (which then gets added to the instance) and then again when you run your program.
If that is what's happening for you, you need to check that you aren't in design mode.
There are a few different ways to check this, depending on context - see How to tell if .NET code is being run by Visual Studio designer

Resources