I’m working on a Delphi script for Altium that creates a pop-up dialog (form) for users to input parameters for resistor components in a schematic library. The script iterates through components and updates their parameters based on user input from TEdit components on the form.
Here’s my problem: the script works fine for the first two iterations of the loop, but on the third iteration, it crashes with what I’m assuming is an Access violation error. The issue seems to be that CurrInput is nil starting from the third iteration. CurrInput.Name and CurrInput.Text are “undeclared identifiers”
I’ve ensured that all TEdit components are properly created and added to the form. I’ve also added debugging messages to verify the initialization of these components. Despite these efforts, the issue persists.
Here’s a snippet of the problematic part of the code:
`
//update parameters when Update button is clicked
procedure TRESinputparamsForm.bUpdateClick(sender : TObject);
begin close;
//create list of params to update as TEdit objects (input boxes from dialog) [CurrInput]
DialogInputsList := TList.Create;
DialogInputsList.Add(PartType);
DialogInputsList.Add(Resistance);
DialogInputsList.Add(Tolerance); //etc…
//create list of param names to index from [CurrDialogParamName]
ParamNameList := TStringList.Create;
ParamNameList.Add(‘PartType’);
ParamNameList.Add(‘Resistance’);
ParamNameList.Add(‘Tolerance’); //etc…
//for every param in DialogInputs list, check if it is in component already
for I := 0 to (DialogInputsList.Count-1) do
begin
CurrInput := DialogInputsList[I];
CurrDialogParamName := ParamNameList[I];//create parameter iterator for current component
ParameterIterator := component.SchIterator_Create;
ParameterIterator.AddFilter_ObjectSet(MkSet(eParameter));
param := ParameterIterator.FirstSchObject;
//iterate through parameters of component to find curr param from dialog
paramFound := false;
while (param <> nil) and (CurrInput.Text <> '') do
begin
paramName := param.Name;
//if param is found in component, update param value from dialog
if (paramName = CurrDialogParamName) then
begin
SchServer.RobotManager.SendMessage(param.I_ObjectAddress, c_BroadCast, SCHM_BeginModify, c_NoEventData);
param.Text := CurrInput.Text;
SchServer.RobotManager.SendMessage(param.I_ObjectAddress, c_BroadCast, SCHM_EndModify, c_NoEventData);
param.ShowName := false;
param.IsHidden := true;
paramFound := true;
break;
end;
//check next parameter in component
param := ParameterIterator.NextSchObject;
end;
//if param not found in component, create parameter object then update value from dialog
if not paramFound then
begin
newParam := SchServer.SchObjectFactory(eParameter, eCreate_Default);
newParam.Name := CurrDialogParamName;
newParam.Text := CurrInput.Text;
newParam.ShowName := false;
newParam.IsHidden := true;
component.AddSchObject(newParam);
SchServer.RobotManager.SendMessage(component.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, newParam.I_ObjectAddress);
end;
component.SchIterator_Destroy(ParameterIterator);
end;
DialogInputsList.Free;
ParamNameList.Free;
end;`
I created an MVP with just one parameter, and that worked fine both updating a value for components where the parameter already existed, and creating the parameter before adding the value. This works just fine on my small testing SchLib. When I run this larger code built from the MVP, it runs through the first two iterations (parameters PartType and Resistance) but breaks on the third iteration with an error that CurrInput (curr parameter to update, TEdit) is “undeclared identifier” and CurrInput.Text can’t be accessed.