DelphiScript for Input Parameters in Altium - Access Violation Err - Page 1
Forum section: electronics / general

author: sureimthere
author_rank: Newbie
timestamp: July 08, 2024, 03:58:50 pm
content: Hi everyone,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 clickedprocedure TRESinputparamsForm.bUpdateClick(sender : TObject);begin close;//create list of params to update as TEdit objects (input boxes from dialog) DialogInputsList := TList.Create;DialogInputsList.Add(PartType);DialogInputsList.Add(Resistance);DialogInputsList.Add(Tolerance);//etc...//create list of param names to index from 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 alreadyfor I := 0 to (DialogInputsList.Count-1) dobeginCurrInput := DialogInputsList;CurrDialogParamName := ParamNameList;//create parameter iterator for current componentParameterIterator := component.SchIterator_Create;ParameterIterator.AddFilter_ObjectSet(MkSet(eParameter));param := ParameterIterator.FirstSchObject;//iterate through parameters of component to find curr param from dialogparamFound := false;while (param <> nil) and (CurrInput.Text <> '') dobeginparamName := param.Name;//if param is found in component, update param value from dialogif (paramName = CurrDialogParamName) thenbeginSchServer.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 componentparam := ParameterIterator.NextSchObject;end;//if param not found in component, create parameter object then update value from dialogif not paramFound thenbeginnewParam := 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;//destroy parameter iterator for current componentcomponent.SchIterator_Destroy(ParameterIterator);end;DialogInputsList.Free;ParamNameList.Free;end;

author: Pseudobyte
author_rank: Frequent Contributor
timestamp: July 15, 2024, 08:15:30 pm
content: I would strongly recommend reaching out to Altium to gain access to their SDK. Your organization will need to sign a licensing agreement, but then you can work in C# instead. With that change you gain the typing information available in the dlls.