Author Topic: DelphiScript for Input Parameters in Altium - Access Violation Err  (Read 209 times)

kosthala1 and 2 Guests are viewing this topic.

Offline sureimthereTopic starter

  • Newbie
  • Posts: 1
  • Country: us
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 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;
        CurrDialogParamName := ParamNameList;//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;     
//destroy parameter iterator for current component
        component.SchIterator_Destroy(ParameterIterator);
    end;
    DialogInputsList.Free;
    ParamNameList.Free;
end;



 

Offline Pseudobyte

  • Frequent Contributor
  • **
  • Posts: 288
  • Country: us
  • Embedded Systems Engineer / PCB Designer
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.
“They Don’t Think It Be Like It Is, But It Do”
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf